What is the difference between these two output.path webpack configurations?

时间:2019-02-24 03:08:22

标签: webpack

What is the difference between using path.resolve(__dirname, 'dist') and ./dist in the output.path webpack configuration?

1 个答案:

答案 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():

使用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命令都没有关系。