const path = require('path')
const webpack = require('webpack')
const package = require('../package.json')
const ParallelUglifyPlugin = require('webpack-parallel-uglify-plugin') //若是没安装过,须要安装一下
module.exports = {
entry: {
vendor:Object.keys(package.dependencies).filter((item) => {
return item !='vue'
})
},
output: {
path: path.join(__dirname, '../static'),
filename: 'dll.[name]_[hash:6].js',
library: '[name]_[hash:6]',
},
plugins: [
new ParallelUglifyPlugin({
cacheDir: '.cache/',
uglifyJS:{
output: {
comments: false
},
compress: {
warnings: false,
drop_debugger: true,
drop_console: true
}
}
}),
new webpack.DllPlugin({
path: path.join(__dirname, '../', '[name]-manifest.json'),
name: '[name]_[hash:6]'
})
]
}
复制代码
const manifest = require('../vendor-manifest.json')
module.exports={
<!--去掉原来的vender字段-->
entry: {
app: './src/main.js'
},
plugins: [
new webpack.DllReferencePlugin({
manifest:manifest
}),
]
}
复制代码
"scripts":{
"build:dll": "webpack --config build/webpack.dll.config.js -p"
}
复制代码
跑完以后,生成 vender-manifest.json 和 dll.vendor.js 文件html
在index.html中 引入vue
<script src="/static/dll.vendor.js"></script>
复制代码
以上都完成以后,之后打包npm run build 的时候就能够不打包引入的第三方插件,由于已经提早打包好了,能够提升一点打包速度。webpack