标签:yarn optimize runtime content 替代 找不到 common chunk update
npm update
npm install webpack-cli
extract-text-webpack-plugin
使用 mini-css-extract-plugin
替代
// 使用yarn
yarn remove extract-text-webpack-plugin
yarn add --dev mini-css-extract-plugin
// webpack3x
const ExtractTextPlugin = require(‘extract-text-webpack-plugin‘);
if (options.extract) {
return ExtractTextPlugin.extract({
use: loaders,
allback: ‘vue-style-loader‘
})
} else {
return [‘vue-style-loader‘].concat(loaders)
}
// 改为
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
if (options.extract) {
return [MiniCssExtractPlugin.loader].concat(loaders)
} else {
return [‘vue-style-loader‘].concat(loaders)
}
// webpack.prod.conf.js
const ExtractTextPlugin = require(‘extract-text-webpack-plugin‘);
new ExtractTextPlugin({
filename: utils.assetsPath(‘css/[contenthash].css‘)
})
// 改为
const MiniCssExtractPlugin = require(‘mini-css-extract-plugin‘);
new MiniCssExtractPlugin({
filename: utils.assetsPath(‘css/[contenthash].css‘)
})
// 在入口之前 添加 新版webpack强制要求添加,不添加也可以执行,会有警告
module.exports = {
mode: process.env.NODE_ENV, // development || production || none
...
}
// 在webpack.dev.conf.js 和 webpack.prod.conf.js 中的plugins下 添加(只是单纯的添加) 如下配置
new webpack.LoaderOptionsPlugin({ options: {} })
new webpack.optimize.CommonsChunkPlugin({
name: ‘vendor‘,
minChunks: function (module, count) {
// 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.CommonsChunkPlugin({
name: ‘manifest‘,
chunks: [‘vendor‘]
})
// 把上面的删除了 --- 然后在 plugins 的同级 添加
optimization: {
runtimeChunk: {
name: ‘manifest‘
},
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: ‘vendor‘,
chunks: ‘all‘
}
}
}
}
// 后面的这个配置如果配置有误会提示 ERROR in chunk 【你的多页面模块名】 [entry] 报错
// 针对代码压缩报错
yarn add --dev uglifyjs-webpack-plugin
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
},
sourceMap: true
})
// 改为
const UglifyJsPlugin = require(‘uglifyjs-webpack-plugin‘);
new UglifyJsPlugin({
uglifyOptions: {
compress: {
warnings: false
}
},
sourceMap: true
})
webpack中文网:https://www.webpackjs.com/
npm官网: https://www.npmjs.com/ 查看新安装的包的使用方法
其他博客:...
标签:yarn optimize runtime content 替代 找不到 common chunk update
原文地址:https://www.cnblogs.com/yejiang1015/p/9091322.html