Hi all, I'm using the latest version of vue-client. I tried to upgrade the webpack version from 3.6 to the latest stable (4.16.1). But when I'm trying to build the project, I have the following error:
Error: webpack.optimize.CommonsChunkPlugin has been removed, please use config.optimization.splitChunks instead.
at Object.get [as CommonsChunkPlugin] (/Users/brunopistone/Developer/nearmeinc/atomyc_ass/node_modules/webpack/lib/webpack.js:173:10)
at Object.<anonymous> (/Users/brunopistone/Developer/nearmeinc/atomyc_ass/build/webpack.prod.conf.js:82:26)
at Module._compile (module.js:649:30)
at Object.Module._extensions..js (module.js:660:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:501:12)
at Function.Module._load (module.js:493:3)
at Module.require (module.js:593:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/brunopistone/Developer/nearmeinc/atomyc_ass/build/build.js:12:23)
at Module._compile (module.js:649:30)
at Object.Module._extensions..js (module.js:660:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:501:12)
at Function.Module._load (module.js:493:3)
at Function.Module.runMain (module.js:690:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `node build/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Anyone can help me? thanks for your support
Take a look at https://webpack.js.org/migrate/4/. I think this will help you.
Shouldn't this template use Webpack 4 anyway?
Anyone else successfully upgraded to webpack 4 with this template? Kind of struggling with this.
I am struggling with this problem too. npm run build does not work. I can not find how to update the webpack.prod.conf.js file which uses CommonsChunkPlugin.
I would be happy if anyone helps me to resolve this problem.
Need to use optimization.splitchunks, please refer to webpack example。
For anyone who has the struggle of replacing CommonsChunkPlugin. Here is a diff of my working config. MiniCssExtractPlugin is also needed.
diff --git a/build/utils.js b/build/utils.js
index e534fb0..9f2e26b 100644
--- a/build/utils.js
+++ b/build/utils.js
@@ -1,7 +1,7 @@
'use strict'
const path = require('path')
const config = require('../config')
-const ExtractTextPlugin = require('extract-text-webpack-plugin')
+const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const packageConfig = require('../package.json')
exports.assetsPath = function (_path) {
@@ -45,10 +45,9 @@ exports.cssLoaders = function (options) {
// Extract CSS when that option is specified
// (which is the case during production build)
if (options.extract) {
- return ExtractTextPlugin.extract({
- use: loaders,
- fallback: 'vue-style-loader'
- })
+ return [
+ MiniCssExtractPlugin.loader,
+ ].concat(loaders)
} else {
return ['vue-style-loader'].concat(loaders)
}
diff --git a/build/webpack.prod.conf.js b/build/webpack.prod.conf.js
index 8553bb0..a2c388b 100644
--- a/build/webpack.prod.conf.js
+++ b/build/webpack.prod.conf.js
@@ -7,7 +7,7 @@ const merge = require('webpack-merge')
const baseWebpackConfig = require('./webpack.base.conf')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
-const ExtractTextPlugin = require('extract-text-webpack-plugin')
+const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const { VueLoaderPlugin } = require('vue-loader')
@@ -28,6 +28,18 @@ const webpackConfig = merge(baseWebpackConfig, {
filename: utils.assetsPath('js/[name].[chunkhash].js'),
chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
},
+ optimization: {
+ runtimeChunk: 'single', // enable "runtime" chunk
+ splitChunks: {
+ cacheGroups: {
+ vendor: {
+ test: /[\\/]node_modules[\\/]/,
+ name: 'vendor',
+ chunks: 'all'
+ }
+ }
+ }
+ },
plugins: [
new VueLoaderPlugin(),
// http://vuejs.github.io/vue-loader/en/workflow/production.html
@@ -43,14 +55,8 @@ const webpackConfig = merge(baseWebpackConfig, {
sourceMap: config.build.productionSourceMap,
parallel: true
}),
- // extract css into its own file
- new ExtractTextPlugin({
+ new MiniCssExtractPlugin({
filename: utils.assetsPath('css/[name].[contenthash].css'),
- // Setting the following option to `false` will not extract CSS from codesplit chunks.
- // Their CSS will instead be inserted dynamically with style-loader when the codesplit chunk has been loaded by webpack.
- // It's currently set to `true` because we are seeing that sourcemaps are included in the codesplit bundle as well when it's `false`,
- // increasing file size: https://github.com/vuejs-templates/webpack/issues/1110
- allChunks: true,
}),
// Compress extracted CSS. We are using this plugin so that possible
// duplicated CSS from different components can be deduped.
@@ -80,36 +86,7 @@ const webpackConfig = merge(baseWebpackConfig, {
new webpack.HashedModuleIdsPlugin(),
// enable scope hoisting
new webpack.optimize.ModuleConcatenationPlugin(),
- // split vendor js into its own file
- new webpack.optimize.CommonsChunkPlugin({
- 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
- )
- }
- }),
- // extract webpack runtime and module manifest to its own file in order to
- // prevent vendor hash from being updated whenever app bundle is updated
- new webpack.optimize.CommonsChunkPlugin({
- name: 'manifest',
- minChunks: Infinity
- }),
- // This instance extracts shared chunks from code splitted chunks and bundles them
- // in a separate chunk, similar to the vendor chunk
- // see: https://webpack.js.org/plugins/commons-chunk-plugin/#extra-async-commons-chunk
- new webpack.optimize.CommonsChunkPlugin({
- name: 'app',
- async: 'vendor-async',
- children: true,
- minChunks: 3
- }),
-
+
// copy custom static assets
new CopyWebpackPlugin([
{
Most helpful comment
For anyone who has the struggle of replacing
CommonsChunkPlugin. Here is a diff of my working config.MiniCssExtractPluginis also needed.