在使用Vue开发项目的过程中, 发现项目打包比较慢, 于是使用DllPlugin
进行预打包
参考方案: https://juejin.im/entry/598bc...
将依赖库打包成dll来引用
打包完成之后在index.html
中引入dll, 发现其他库运行正常, 包括ElementUI
的其他组件也运行正常, 但是Tooltip
组件却不起作用.
如果不打包ElementUI到Dll中, Tooltip 是可以正常使用的
有朋友遇到过这个情况么, 或者说有人知道为什么会这样么?
打包配置代码如下:
webpack.dll.conf.js
const path = require('path');
const webpack = require('webpack');
module.exports = {
entry: {
// 如果把 element-ui 从数组中移除的话, Tooltip 组件能够正常使用
vendor: ['vue/dist/vue.esm.js', 'vue-router','vuex', 'axios', 'underscore'],
},
output: {
path: path.join(__dirname, '../static/js'),
filename: '[name].dll.js',
library: '[name]_library' // vendor.dll.js中暴露出的全局变量名
},
plugins: [
new webpack.DllPlugin({
path: path.join(__dirname, '.', '[name]-manifest.json'),
name: '[name]_library',
context: path.resolve(__dirname, '..')
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
})
]
};
webpack.base.conf.js
var config = require('../config')
var vueLoaderConfig = require('./vue-loader.conf')
function resolve (dir) {
return path.join(__dirname, '..', dir)
}
module.exports = {
entry: {...},
output:{...},
resolve: {...},
module: {...},
plugins: [
new webpack.DllReferencePlugin({
context: path.resolve(__dirname, '..'),
manifest: require('./vendor-manifest.json')
}),
]
}
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
</head>
<body>
<div id="app"></div>
<script src="./static/js/vendor.dll.js"></script>
</body>
</html>
我也出现这样的问题 坐等解答!