1.webpack.config.js中添加:
const path = require('path');
+ const webpack = require('webpack');
const HTMLWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: {
index: './src/index.js',
another: './src/another-module.js'
},
plugins: [
new HTMLWebpackPlugin({
title: 'Code Splitting'
- })
+ }),
+ new webpack.optimize.CommonsChunkPlugin({
+ name: 'common' // 指定公共 bundle 的名稱,
+ })
],
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist')
}
};
2.然后就遇到了一個問題,還給出了一個解決方案,需要去查看檔案中的插件章節

//optimization與plugins同級
optimization: {
splitChunks: {
cacheGroups: {
commons: {
name: "commons",
chunks: "initial",
minChunks: 2
}
}
}
},
3.運行npm run build,如果有公共部分可得到common.bundle.js檔案,如果沒有則不會生成這個檔案

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/168250.html
標籤:JavaScript
上一篇:Vuex基本使用的總結--轉載
下一篇:React入門(一)
