【问题标题】:Can I have webpack emit the bundle to two directories?我可以让 webpack 将包发送到两个目录吗?
【发布时间】:2019-11-30 16:51:37
【问题描述】:

我有这个配置

const DIST_DIR = path.join(__dirname, '/dist');

// ... snip

output: {
  filename: 'bundle.js',
  path: DIST_DIR
},

效果很好。

但是,我也希望将 bundle.js 写入另一条路径。所以它会在 2 个地方发出。

这可能吗?

【问题讨论】:

    标签: javascript json bash webpack configuration


    【解决方案1】:

    如果要将每个条目的输出放在不同的子目录中,可以在文件名中添加路径变量[name]。例如,如果您有两个条目:'bundleOne' 和 'bundleTwo',并且要将它们的输出放到子目录 './bundleOne' 和 './bundleTwo' 中,您可以使用以下配置:

    module.exports = {
      entries: {
        bundleOne: './bundleOne/index.js',
        bundleTwo: './bundleTwo/index.js'
      }
    
    // ... skip
    
      output: {
        filename: '[name]/dist/[name].bundle.js',
        path: __dirname
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-06-12
      • 2018-12-18
      • 1970-01-01
      • 2018-02-04
      • 2011-05-20
      • 1970-01-01
      • 2015-04-03
      相关资源
      最近更新 更多