在chainWebpack中配置
chainWebpack:config => {
const files = fs.readdirSync(path.resolve(__dirname, './dll'))
for (let i = 0; i < files.length; i++) {
if (/.*\.dll.js/.test(files[i])) {
config.plugin('AddAssetHtmlWebpackPlugin' + i).use(require('add-asset-html-webpack-plugin'), [{
filepath: path.resolve(__dirname, 'dll', files[i])
}])
}
if (/.*\.manifest.json/.test(files[i])) {
config.plugin('DllReferencePlugin' + i).use(require('webpack/lib/DllReferencePlugin'), [{
context: __dirname,
manifest: path.resolve(__dirname, 'dll', files[i])
}])
}
}
}
注:本来for循环是用forEach来写的,但是报Cannot assign to read only property 'exports' of object '#<Object>',
百度的是import和module.exports不可以一起使