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

Ale*_*lov 4 configuration command-line-interface webpack vue.js

我有以下内容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']
    }
} 
}
Run Code Online (Sandbox Code Playgroud)

其上npm run build生成:

index1.html 
index2.html 
feature1.js 
feature2.js 
js/chunk-vendors.js
Run Code Online (Sandbox Code Playgroud)

在 dist 文件夹中 ( ../vuejs/)

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

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

Dar*_*ght 5

您可以定义一个显式的chunkFilename; 例如:

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

应该会生成如下内容:

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
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助 :)