在Vue.js CLI(Webpack配置)中更改chunk-vendors.js的路径

时间:2019-05-13 14:23:07

标签: vue.js webpack configuration command-line-interface

我有以下vue.config.js

module.exports = {
filenameHashing: false,
productionSourceMap: false,
outputDir: '../vuejs/',
configureWebpack: {
    devtool: 'source-map',
    output: {
        filename: '[name].js'
    }
},
pages: {
    feature1: {
        entry: 'src/f1.js',
        template: 'public/feature.html',
        filename: 'index1.html',
        title: 'Feature 1',
        chunks: ['chunk-vendors', 'chunk-common', 'feature1']
    },
    feature2: {
        entry: 'src/f2.js',
        template: 'public/feature.html',
        filename: 'index2.html',
        title: 'Feature 2',
        chunks: ['chunk-vendors', 'chunk-common', 'feature2']
    }
} 
}

npm run build上它会生成:

index1.html 
index2.html 
feature1.js 
feature2.js 
js/chunk-vendors.js

在dist文件夹(../vuejs/

如何更改配置,以便将文件chunk-vendors.js放在根文件夹中(feature1.jsfeature2.js所在的位置)。

P.S。 :(额外的问题)我实际上不需要html文件,因为我将vue.js *.js嵌入到现有应用程序中。我可以禁止生成html文件吗?

1 个答案:

答案 0 :(得分:0)

您可以定义一个明确的chunkFilename;例如:

module.exports = {
  outputDir: 'my/custom/build/path/',
  configureWebpack: (config) => {
      config.output.filename = '[name].[hash:8]js';
      config.output.chunkFilename = '[name].[hash:8].js';
  }
}

应该生成类似以下内容的

my/custom/build/path/app.216ad62b.js
my/custom/build/path/app.216ad62b.js.map
my/custom/build/path/chunk-vendors.6f85144f.js
my/custom/build/path/chunk-vendors.6f85144f.js.map

希望这会有所帮助:)