1、plugins 中引入已经生成的vendor_library
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require('./dll/vendor-manifest.json'),
name: "vendor_library",
sourceType : 'vendor_library'
})
2、webpack要生成多个页面
//需要dll的页面
['Admin','Class'].forEach(function(name) {
webpackConfig.entry[name] = './src/'+name+'/index';
const plugin = new HtmlWebpackPlugin({
filename: name + '.html',
template: './public/index.html',
inject: true,
chunks: [name],
});
webpackConfig.plugins.push(plugin);
})
//不需要dll的页面
webpackConfig.entry['classroom'] = './src/Classroom/index';
webpackConfig.plugins.push(
new HtmlWebpackPlugin({
filename: 'classroom.html',
template: 'ejs-render-loader!./src/Classroom/tpl/index.ejs',
inject: true,
chunks: ['classroom']
})
);
3、相关模板
Admin.html、Class.html
script引入dll: <script src="/js/vendor.dll.js"></script>
打包成功,页面运行成功,没有问题
./src/Classroom/tpl/index.ejs
没有引入dll
打包成功,页面运行报错,提示 vendor_library is not definded
4、期望结果
在 classroom 这个页面不引入 dll,页面运行成功。
或者,如何让DllReferencePlugin 只对 chunks ['Admin','Class'],这两个有效。
这个问题解决的如何了