Skip to content
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

[Feature] Webpack 4 upgrade #1562

Closed

Conversation

rodeyseijkens
Copy link

@rodeyseijkens rodeyseijkens commented Mar 6, 2018

  • Updated for webpack 4
  • Upgraded general packages

Home chunk is now handled by webpack and it generates the best chunks together.
Each route has it own chunk now instead of the webpackMode: 'eager'.
Webpack for example creates a "home~about" and a "privacy~login" chunk and the server.js pushes the corresponding chunks to the SSR Html.js depending on the route it has.
This also eliminates the need for an array in the route.chunks, so this is renamed to route.chunk and a string now.

About the WIP part
There is still work that need needs to be done for the upcoming "DeprecationWarning: Tapable.plugin is deprecated. Use new API on .hooks instead". So in the start.js we use the compiler.plugin('compile') for example these still need to be changed to the new API.

If any of you have questions/enhancements please leave a comment
#1549

@tim-soft
Copy link

tim-soft commented Mar 6, 2018

How about side-effects of static render -- anything need to change here?
https://github.com/kriasoft/react-starter-kit/blob/master/tools/render.js

@rodeyseijkens
Copy link
Author

Shouldn’t be any different that before, so not affected.

@rodeyseijkens
Copy link
Author

rodeyseijkens commented Mar 7, 2018

There is still a DeprecationWarning but that might be of one of the plugins, but not entirely sure.

"postcss-loader > schema-utils@0.4.3" has incorrect peer dependency "webpack@^2.0.0 || ^3.0.0"
postcss-loader loads for some reason schema-utils@0.4.3 instead of 0.4.5 which might be a fix but not 100% sure.

@tim-soft On the render question, it is broken, but I what I have seen is that it is even broken on the current master branch so this might need a new PR/Issue for a fix for that.

@langpavel
Copy link
Collaborator

I have seen is that it is even broken on the current master branch so this might need a new PR/Issue for a fix for that.

Can you describe really quickly what is broken?

@rodeyseijkens
Copy link
Author

@langpavel sorry I thought the yarn render also created a build, but it isn't that was the confusion on my end. Forgot about the yarn build --release --static.

@langpavel
Copy link
Collaborator

langpavel commented Mar 7, 2018

@rodeyseijkens Yeah, this should be done some way better 😬 I was surprised by this too 🙂

@rodeyseijkens
Copy link
Author

@langpavel new package.json script maybe?
"build-render": "yarn build --release --static"

@rodeyseijkens
Copy link
Author

Latest commit removed NoEmitOnErrorsPlugin and NamedModulesPlugin cause its not needed or included in dev mode by default see: https://github.com/webpack/webpack/releases

I also pinned down the latest DeprecationWarning: Tapable.plugin, it is not in the RSK code. Its part of the AssetsPlugin. There is an issue open but I'm not entirely sure how fast they are going to fix it... cause it's been a year since an update on the package.

So what will be our status on this with this current PR?

@tim-soft
Copy link

Unfortunately this is the reality for a lot of webpack plugins right now, extract text plugin is keeping me from upgrading on a lot of projects.

Maybe there is an alternative that is v4 friendly such as https://github.com/webdeveric/webpack-assets-manifest

@rodeyseijkens rodeyseijkens changed the title [Feature][Working - WIP] Webpack 4 upgrade [Feature] Webpack 4 upgrade Mar 17, 2018
@rodeyseijkens
Copy link
Author

I implemented the webpack-assets-manifest as suggested by @tim-soft

So everything is now up to date for Webpack 4.0, so in my optinion it would be ready for merge.
@langpavel @koistya @frenzzy

Copy link
Collaborator

@langpavel langpavel left a comment

Choose a reason for hiding this comment

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

Great work. Thanks!

@langpavel langpavel mentioned this pull request Mar 20, 2018
Copy link
Collaborator

@langpavel langpavel left a comment

Choose a reason for hiding this comment

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

route.chunks dropped?

src/server.js Outdated
...Object.keys(assets)
.filter(asset => asset.includes(route.chunk))
.map(chunk => assets[chunk].js),
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

@rodeyseijkens Why did you remove support for route.chunks?
May be wi can support both, chunk and chunks to keep this backward compatible?

@rodeyseijkens
Copy link
Author

rodeyseijkens commented Mar 22, 2018

@langpavel the reason is that Webpack is now intelligent enough to split everything up in chunks that overlap thus you don't need to manually configure / figure out what chunks you want to combine. That is also why the 'eager' feature was dropped cause now it is exactly serving what is needed for that page and thus not any overloading of duplicate chunk data.

If we are going to manually put in more chunks it won't work because Webpack itself now figures out what chunks overlap and needs to be separate.

So for example you have a home, login, admin routes.
home.js will have its own chunk.
login.js will have its own chunk.
admin.js will have its own chunk.
home~login~admin.js is a shared chunk this will be generated by webpack itself cause it for example sees that a lot of componens or functions are shared (header component for example).
login~admin.js also ia a shared chunk and will be generated by webpack (input field component for example).
vendors~login~admin.js is a special vendor chunk specific for those pages (react-forms package that is only used on those pages) (possible when we have no vendor.js separation).

Hope this clears it up.

PS: There is still a bug I saw, it puts the .js.map files in the assets.json so they will be included in the SSR <script/> so need to fix that first.

@tim-soft
Copy link

tim-soft commented Mar 22, 2018

Good catch! Is there a benefit to maintaining separate client and vendor bundles?

edit:
What I mean by separate is the browser will always need to grab these two bundles no matter what(?), so why split into two http requests

@rodeyseijkens
Copy link
Author

@tim-soft Well kind of right I guess, maybe we don't need to have a special configuration then for Webpack splitChunks.

@langpavel
Copy link
Collaborator

@rodeyseijkens

If we are going to manually put in more chunks it won't work because Webpack itself now figures out what chunks overlap and needs to be separate.

I think you are wrong (you may be right but you should proof to me 🙂)
Loading multiple chunks can be implemented and should work IMHO

It is possible to have nested routes.
You can imagine that like page which have some tabs inside, like /admin/dashboard and /admin/articles.
Now you need admin chunk but you also need dashboard or articles chunk.
How you can do this with only one chunk? (Yes, I know, there can be potentially better way to do this, but not always I think)

@langpavel langpavel closed this in 84f9d5e Mar 24, 2018
@langpavel
Copy link
Collaborator

Merged 🎉

@rodeyseijkens rodeyseijkens deleted the feature/webpack-4-upgrade branch March 27, 2018 10:05
n-parasochka pushed a commit to n-parasochka/react-starter-kit that referenced this pull request Apr 29, 2019
* Updated for webpack 4
* Updated start.js with webpack 4 hooks API
* Removed NoEmitOnErrorsPlugin and NamedModulesPlugin
* Updated Layout.test to have mocked pathname in context
* Removed "assets-webpack-plugin" in favour of "webpack-assets-manifest"
* Changed `vendor.js` → `vendors.js` — naming consistency with webpack
* `assets.json` → `asset-manifest.json`
* new file `chunk-manifest.json` for SSR support

Closes kriasoft#1562, kriasoft#1549
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants