我使用vue-cli 2.9.6
,并使用vue init webpack <project name>
创建的VUE项目。
当我打电话vue run build
,它创造了许多不同的js文件(和名称每一次改变...):
vendor.20d54e752692d648b42a.js
vendor.20d54e752692d648b42a.js.map
app.ed70f310595763347909.js
app.ed70f310595763347909.js.map
manifest.2ae2e69a05c33dfc65f8.js
manifest.2ae2e69a05c33dfc65f8.js.map
也CSS像这样的文件:
app.a670fcd1e9a699133143a2b144475068.css
app.a670fcd1e9a699133143a2b144475068.css.map
我想输出仅仅是2个文件:
build.js { for all js }
styles.css { for all css }
我怎样才能做到这一点?
webpack.prod.conf.js
下面的代码 // split vendor js into its own file
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks (module) {
// any required modules inside node_modules are extracted to vendor
return (
module.resource &&
/\.js$/.test(module.resource) &&
module.resource.indexOf(
path.join(__dirname, '../node_modules')
) === 0
)
}
}),
// extract webpack runtime and module manifest to its own file in order to
// prevent vendor hash from being updated whenever app bundle is updated
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest',
minChunks: Infinity
}),
config/index.js
变量productionSourceMap
设置sourceMaps从true
到false
entry
和output
properties:entry: {
build: './src/main.js'
},
output: {
path: config.build.assetsRoot,
filename: utils.assetsPath('js/[name].js'),
chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
},
ExtractTextPlugin
in选项的更新名称webpack.prod.conf.js到filename: utils.assetsPath('css/styles.css'),