What is the difference between using path.resolve(__dirname, 'dist')
and ./dist
in the output.path
webpack configuration?
答案 0 :(得分:0)
如果您的webpack.config.js
位于代码的基本文件夹中,则它们可能会产生相同的结果。
.dist
文件夹:这意味着Webpack将在此process.cwd() + 'dist'
文件夹中发出输出。 process.cwd()
返回当前工作目录。
方案1:
Webpack.config.js
路径:c:\work\project\scripts\webpack.config.js
webpack --config scripts\webpack.config.js
c:\work\project
c:\work\project\dist\**
方案1:
Webpack.config.js
路径:c:\work\project\scripts\webpack.config.js
webpack --config scripts\webpack.config.js
c:\work\project\scripts
c:\work\project\scripts\dist\**
使用path.resolve(__dirname, 'dist')
意味着Webpack将在__dirname + './dist'
文件夹中发出输出。 __dirname
是Node.js中模块级别的全局变量,它返回当前模块的目录名称。
这意味着如果您的Webpack.config.js
的路径为c:\work\project\scripts\webpack.config.js
,则Webpack将在以下路径生成dist文件夹:c:\work\project\scripts\dist\**
。从何处执行Webpack命令都没有关系。