之前的文章《你值得了解的vim中文乱码的问题(分享)》中,给大家了解了vim中文乱码的问题。下面本篇文章给大家了解webpack3升级到webpack4版本遇到的问题,伙伴们来看看吧。
据说webpack3比webpack4编译速度将近快了 60%-80%。
成功升级之后,于是来记录下,项目主要是vue ^2.5.9,webpack ^4.10.2,webpack-dev-sever ^3.1.4,配合升级的还有vue-loader ^15
项目重现编译之后由原来的1.7mb减少到1.1mb,看来在压缩这块也是由效果的。
需要修改的地方有以下几点:
vue-loader14到15需要增加如下配置
const vueloaderplugin = require('vue-loader/lib/plugin') ++++const minicssextractplugin = require('mini-css-extract-plugin') // webpack 4 +++const extracttextplugin = require('extract-text-webpack-plugin') //for webpack3 -----module.exports = {...plugins: [ + new vueloaderplugin(), ++++ + new minicssextractplugin({filename:'mian.css'}) //for webpack 4 +++ - new extracttextplugin({filename:'main.css'}) //for webpack 3 ---]...}
webpack-dev-server升级之后需做如下改动
devserver: { ++ contentbase: path.resolve(__dirname, '../dos-html'), // 需要指定路径 ++ port: 7001, hot: true, // open: false, inline: true, compress: true, historyapifallback: true, .... },
webpack3升级4之后需要改动的配置
plugins: [ //已经移除 new webpack.optimize.commonschunkplugin({ name: 'vendor', minchunks: function (module) { // any required modules inside node_modules are extracted to vendor return ( module.resource && /\.js$/.test(module.resource) && module.resource.indexof( path.join(__dirname, '../node_modules')) === 0 ) } }), new webpack.optimize.uglifyjsplugin(...)//已经移除}// ===> 修改为以下const uglifyjsplugin = require('uglifyjs-webpack-plugin');moudel.exports = {mode: 'production', ++ 这里指定模式。...optimization: { splitchunks: { name(module) { return ( module.resource && /\.js$/.test(module.resource) && module.resource.indexof(path.join(__dirname, '../node_modules')) === 0 ) } }, minimize: true, minimizer: [ new uglifyjsplugin({ uglifyoptions: { compress: { warnings: false, // drop_debugger: true, // drop_console: true }, sourcemap: false } }) ] },...}
其他的各种报错信息,注意看,可能是模块版本太低了吧,都升级下就ok了。
【完】
推荐学习:web pack入门视频教程
以上就是解析webpack3升级到webpack4版本遇到的问题(总结)的详细内容。
