Nuxt.js: ✨ Webpack 4 upgrade

Created on 25 Jan 2018  ·  24Comments  ·  Source: nuxt/nuxt.js

Webpack 4 beta just released and no features/breaking-changes planned for final release. The hardest part for the upgrade is plugins that need to adapt to new hooks system. We have about 1 month time remaining to the final release of webpack and (hopefully) until then all of the webpack plugins used by nuxt.js will be compatible with 4.x.

PR: #2901 - Status: Done

Branch: feat/webpack4

Resources

Pending plugins

extract-text-webpack-plugin

Upgrade:

PR: webpack-contrib/extract-text-webpack-plugin#707 - Status: merged

NPM Release: v4.0.0-alpha.0

Problem with ModuleConcatination:

PR: webpack/webpack#6597 - Status: open

Fixed in webpack-contrib/extract-text-webpack-plugin#728

html-webpack-plugin

PR: jantimon/html-webpack-plugin#823 - Status: open

PR: webpack-contrib/html-webpack-plugin/pull/3 - Status: merged

NPM Release: 3.0.6 released!

time-fix-plugin

PR: egoist/time-fix-plugin#1 - Status: merged

This feature request is available on Nuxt.js community (#c2335)
available soon enhancement

Most helpful comment

@pSchaub We are on it ;)

All 24 comments

Maybe is a good moment to rethink about plugins system basis. Most of the time I have this in my nuxt.config.js: plugins: [ { src: '~plugins/nossr', ssr: false } ] and just one nossr.js file for all of them. But I did not really check ssr-ok-plugins.

Webpack 4 is released now. Let's upgrade!

@pSchaub We are on it ;)

@pi0
ModuleConcatination issue has been fixed in https://github.com/webpack-contrib/extract-text-webpack-plugin/pull/728

it is already shipped on latest version?

Only nuxt-edge. Will be shipped with nuxt 2

@pi0 thanks, I tried and only vendor is deprecated there. but, there is any documentation to use the nuxt-edge?

thanks, migrating now.

compiler.hooks.compilation.tap('NetlifyServerPushPlugin', compilation => {
      compilation.hooks.htmlWebpackPluginBeforeHtmlGeneration.tap(
        'NetlifyServerPushPlugin',
        data => {
          const assets = data.assets;
          const source = this.generateAssetHeaders(assets);
          compilation.assets[`${this.options.headersFile}`] = {
            source: () => source,
            size: () => source.length,
          };
        }
      );
    });
}

i have a problem, htmlWebpackPluginBeforeHtmlGeneration is not exists on webpack. implementing above code not working on nuxt-edge

@ekoeryanto
How about to use compilation.hooks.htmlWebpackPluginBeforeHtmlProcessing.tapAsync

https://github.com/jantimon/html-webpack-plugin/issues/871#issuecomment-369585543

same error with htmlWebpackPluginBeforeHtmlProcessing
and in console.log(compilation.hooks) there is no htmlWebpackPlugin* exists

Did you install html-webpack-plugin in your own package.json and which version are you using?

htmlWebpackPluginBeforeHtmlProcessing was introduced since 3.0.0 https://github.com/jantimon/html-webpack-plugin/blob/v3.0.0/index.js#L58

no, I did not install html-webpack-plugin my self as it is already covered by nuxt

@ekoeryanto Can you please provide a repo to reproduce you issue?

@clarkdo here https://github.com/pakeweb/apek/tree/develop
I commented out plugin section in nuxt.config.js

@ekoeryanto
Sorry for the late reply, I'm kind of busy with my personal stuff recent days.
Could you please open an issue and cc to me in case that I won't forget it.

done #3254

On the Nuxt website it says version 2.0, but build vendor is still on the site, a bit misleading isn't it? https://nuxtjs.org/api/configuration-build/#vendor. Well now that I am using [email protected], I have removed vendor, but unfortunately I do not know where I am to place my local vendor js so it builds on my page. I suggest the documentation say that vendor is deprecated with a suggestion on what to use instead.

@david-j-davis Thanks for the suggestion!

You can control you chunks now fine-grained with webpack 4 and splitChunks (docs for this plugin).

By default, several common dependencies are bundled source code.

Thanks @manniL, I'll look into it, and do we need to install the webpack package as well or is that bundled already in nuxt?

@david-j-davis No, you don't need to install that package. It already comes (with a decent configuration for most use cases) with Nuxt 2 ☺️ )

Ok thanks @manniL !

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

VincentLoy picture VincentLoy  ·  3Comments

vadimsg picture vadimsg  ·  3Comments

nassimbenkirane picture nassimbenkirane  ·  3Comments

bimohxh picture bimohxh  ·  3Comments

vadimsg picture vadimsg  ·  3Comments