先执行webpack.dll.js
const path = require('path');
const webpack = require('webpack');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = {
entry:{
vendor:['./src/vendor/index.js']
},
output:{
filename: '[name].dll2.js',
path: path.resolve(__dirname,'dll'),
library: "[name]_library",
},
plugins:[
new CleanWebpackPlugin(),
new webpack.DllPlugin({
path: __dirname + "/dll/[name]-manifest.json",
name: "[name]_library"
})
]
}
其次执行webpack.config.js
这里引入了vendor-manifest.json来自webpack.dll.js生成的
config.plugins.push(new webpack.DllReferencePlugin({
manifest: require("./dll/vendor-manifest.json") // eslint-disable-line
}))