Skip to content

webpack 4 upgrade #293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions build/webpack.base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,16 @@ module.exports = {
maxEntrypointSize: 300000,
hints: isProd ? 'warning' : false
},
mode: process.env.NODE_ENV || 'production',
plugins: isProd
? [
new webpack.optimize.UglifyJsPlugin({
compress: { warnings: false }
}),
new webpack.optimize.ModuleConcatenationPlugin(),
new ExtractTextPlugin({
filename: 'common.[chunkhash].css'
filename: 'common.[chunkhash].css',
allChunks: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"extract-text-webpack-plugin" get error : TypeError: Cannot read property 'call' of undefined
Fixing it, by adding allChunks: true
webpack/webpack#959

Copy link

@asadsahi asadsahi Mar 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RezaHaidari I can't see any issues with existing ExtractTextPlugin config. Also following config isn't needed as well I guess as by setting mode to production it minifies the code anyway.

if (isProd) {
  config.optimization = {
    ...config.optimization,
    minimizer: [
      new UglifyJsPlugin({
        sourceMap: true,
        uglifyOptions: {
          compress: {
            inline: false,
          },
        },
      }),
    ],
  };
}

Any comments?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

})
]
: [
new FriendlyErrorsPlugin()
]
}
}
43 changes: 24 additions & 19 deletions build/webpack.client.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,31 @@ const config = merge(base, {
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the default NODE_ENV is not same as mode? And it can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, you right

'process.env.VUE_ENV': '"client"'
}),
// extract vendor chunks for better caching
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: function (module) {
// a module is extracted into the vendor chunk if...
return (
// it's inside node_modules
/node_modules/.test(module.context) &&
// and not a CSS file (due to extract-text-webpack-plugin limitation)
!/\.css$/.test(module.request)
)
}
}),
// extract webpack runtime & manifest to avoid vendor chunk hash changing
// on every build.
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest'
}),

new VueSSRClientPlugin()
]
],
optimization:{
runtimeChunk: {
name: "manifest"
},
// extract webpack runtime & manifest to avoid vendor chunk hash changing
// on every build.
// extract vendor chunks for better caching
splitChunks:{
chunks:"initial",
cacheGroups: {
vendors: function (module) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried your code using webpack 4.23.1 and it fails with a "TypeError: cacheGroup.getName is not a function"
The correct form for cacheGroups entries seems different (see https://webpack.js.org/plugins/split-chunks-plugin/#splitchunks-cachegroups)

  vendors: {
    test: function(module) {

// a module is extracted into the vendor chunk if...
return (
// it's inside node_modules
/node_modules/.test(module.context) &&
// and not a CSS file (due to extract-text-webpack-plugin limitation)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

due to extract-text-webpack-plugin limitation

I wondering if mini-css-extract-plugin has the same limitation ?

!/\.css$/.test(module.request)
)
}
}
}
},
})

if (process.env.NODE_ENV === 'production') {
Expand Down
Loading