mini-css-extract-plugin替换extract-text-webpack-plugin
修改配置
1.utils.js
注释调extract-text-webpack-plugin相关代码
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
if (options.extract) {
// return ExtractTextPlugin.extract({
// use: loaders,
// fallback: 'vue-style-loader'
// })
return [MiniCssExtractPlugin.loader].concat(loaders)
} else {
return ['vue-style-loader'].concat(loaders)
}
image.png
// const ExtractTextPlugin = require('extract-text-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
module.exports添加
optimization: {
splitChunks: {
cacheGroups: {
styles: {
name: 'styles',
test: /\.css$/,
chunks: 'all',
enforce: true
}
}
}
},
plugins里添加
new MiniCssExtractPlugin({
filename: utils.assetsPath('css/[name].[contenthash].css'),
}),
],
plugins里这几项注释
// new webpack.optimize.ModuleConcatenationPlugin(),// xxx
// split vendor js into its own file
// new webpack.optimize.CommonsChunkPlugin({// xxx
// name: 'vendor',
// minChunks(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.CommonsChunkPlugin({// xxx
// name: 'manifest',
// minChunks: Infinity
// }),
// new webpack.optimize.CommonsChunkPlugin({// xxx
// name: 'app',
// async: 'vendor-async',
// children: true,
// minChunks: 3
// }),
参考文章
https://www.jianshu.com/p/826e0e80922f(参考的依赖包)
https://www.jianshu.com/p/879517859fc3(可以解决大部分报错)
可能碰见报错
image.png
解决办法:vue-loader的版本不适配导致,原版本13升至15.7.1报这个错,后面改成14.2.2版本就好了
最终各依赖版本版本
{
"name": "tts_evaluate",
"version": "1.0.0",
"description": "A Vue.js project",
"author": "",
"private": true,
"scripts": {
"dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
"start": "npm run dev",
"build": "node build/build.js"
},
"dependencies": {
"@fullcalendar/core": "^5.3.1",
"@fullcalendar/daygrid": "^5.3.2",
"@fullcalendar/interaction": "^5.3.1",
"@fullcalendar/vue": "^5.3.1",
"axios": "^0.18.0",
"echarts": "^4.2.1",
"element-ui": "^2.4.11",
"jsencrypt": "^3.0.0-rc.1",
"less": "^3.9.0",
"less-loader": "^5.0.0",
"qs": "^6.6.0",
"vue": "^2.6.10",
"vue-dompurify-html": "^2.3.0",
"vue-router": "^3.0.1",
"vuex": "^3.1.1",
"wavesurfer.js": "^3.0.0"
},
"devDependencies": {
"autoprefixer": "^7.1.2",
"babel-core": "^6.22.1",
"babel-helper-vue-jsx-merge-props": "^2.0.3",
"babel-loader": "^7.1.1",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"babel-plugin-syntax-jsx": "^6.18.0",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-plugin-transform-vue-jsx": "^3.5.0",
"babel-preset-env": "^1.3.2",
"babel-preset-stage-2": "^6.22.0",
"chalk": "^2.0.1",
"copy-webpack-plugin": "^4.0.1",
"css-loader": "^1.0.1",
"file-loader": "^1.1.4",
"friendly-errors-webpack-plugin": "^1.6.1",
"html-webpack-plugin": "^3.2.0",
"mini-css-extract-plugin": "^0.4.0",
"node-notifier": "^5.1.2",
"optimize-css-assets-webpack-plugin": "^5.0.1",
"ora": "^1.2.0",
"portfinder": "^1.0.13",
"postcss-import": "^11.0.0",
"postcss-loader": "^3.0.0",
"postcss-url": "^7.2.1",
"rimraf": "^2.6.0",
"semver": "^5.3.0",
"shelljs": "^0.7.6",
"uglifyjs-webpack-plugin": "^1.1.1",
"url-loader": "^0.5.8",
"vue-loader": "^14.2.2",
"vue-style-loader": "^4.1.2",
"vue-template-compiler": "^2.6.10",
"webpack": "^4.39.3",
"webpack-bundle-analyzer": "^2.9.0",
"webpack-cli": "^3.3.8",
"webpack-dev-server": "^3.8.0",
"webpack-merge": "^4.1.0"
},
"engines": {
"node": ">= 6.0.0",
"npm": ">= 3.0.0"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]
}
项目目录结构
image.png