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

webpack 4 upgrade #293

wants to merge 3 commits into from

Conversation

RezaHaidari
Copy link
Contributor

No description provided.

@asadsahi
Copy link

asadsahi commented Mar 5, 2018

great job @RezaHaidari works perfect for me. I have just upgraded based on your changes a project which is based on vue-hackernews.

@asadsahi
Copy link

asadsahi commented Mar 5, 2018

@RezaHaidari in webpack.base.config.js you have added uglifyjsplugin with sourcemaps:


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

But it doesn't generate any sourcemaps, alos, how different is it compared to default optimisation webpack 4 does in --mode=production?

@sirlancelot
Copy link
Contributor

CommonsChunkPlugin is no longer needed, nor is UglifyJsPlugin. All of those options are abstracted in to options.optimization. They are activated depending on options.mode which should be set to either "development" or "production"

@asadsahi
Copy link

asadsahi commented Mar 5, 2018

@sirlancelot you are right. But I was also wondering how to enable sourcemaps in production with --mode=production. First I though this pull request is achiving that with uglifyjsplugin, but there must be an lternative with defaults.

@@ -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

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.

package.json Outdated
@@ -4,7 +4,7 @@
"author": "Evan You <[email protected]>",
"private": true,
"scripts": {
"dev": "node server",
"dev": "cross-env NODE_ENV=development node server",
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?

@asadsahi asadsahi mentioned this pull request Mar 7, 2018
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) {

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants