var webpack = require('webpack') var path = require('path') module.exports = { mode: 'development', entry: { 'pageA': './src/pageA' }, output: { path: path.resolve(__dirname, './dist'), filename: '[name].bundle.js', chunkFilename: '[name].chunk.js' }, plugins: [ new webpack.optimize.CommonsChunkPlugin({ name: 'common', minChunk: 2 }) ], devtool: 'source-map', }
splitChunks: { chunks: "all", cacheGroups: { libs: { name: "chunk-libs", test: /[\/]node_modules[\/]/, priority: 10, chunks: "initial" // 只打包初始時依賴的第三方 }, elementUI: { name: "chunk-elementUI", // 單獨將 elementUI 拆包 priority: 20, // 權重要大於 libs 和 app 否則會被打包進 libs 或者 app test: /[\/]node_modules[\/]element-ui[\/]/ }, commons: { name: "chunk-comomns", test: resolve("src/components"), // 可自定義拓展你的規則 minChunks: 2, // 最小共用次數 priority: 5, reuseExistingChunk: true } } };