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

Update to Webpack 4 #1052

Merged
merged 39 commits into from
Oct 24, 2018
Merged

Update to Webpack 4 #1052

merged 39 commits into from
Oct 24, 2018

Conversation

ZhangYiJiang
Copy link
Member

@ZhangYiJiang ZhangYiJiang commented Jul 22, 2018

Closes #874

Upgrade notes

  • Create React App has not upgraded for Webpack 4, so some of their plugins will raise a warning or cannot be used at all. None of the plugins are critical though, so it's fine
  • Cache loader has been removed for HardSourcePlugin. The result should actually be faster, but please help test with your computers. Focus is on hot reloading performance first and prod build performance second
  • AutoDllPlugin has been removed. It's not compatible for some reason.
  • LodashWebpackPlugin has been removed.
  • OptimizeCSSAssetsPlugin is removed. For some reason the plugin is stripping sourcemaps. cssnano is used directly, so it is now configured in postcssrc.js
  • The main entry chunk is now inlined directly into index.html. This should improve performance slightly
  • Webpack's new chunking algorithm means our split chunks have more files before since they're split between vendor and app code, whereas before they were together. Performance and size should still be roughly the same.

@mods-bot
Copy link

mods-bot commented Jul 22, 2018

Deploy preview for nusmods ready!

Built with commit 0d33fd7

https://deploy-preview-1052--nusmods.netlify.com

@ZhangYiJiang
Copy link
Member Author

Hmmm, the file size is slightly bigger. Will investigate.

@taneliang
Copy link
Member

Does yarn start work for you? I'm getting a "Module not found. Error: Can't resolve 'cache-loader'` error on both my laptop and desktop.

@ZhangYiJiang
Copy link
Member Author

That's odd. Cache loader should be removed from all configs. Check if I forgot to remove them from somewhere?

@taneliang
Copy link
Member

Found it. I'll remove it and push

@ZhangYiJiang
Copy link
Member Author

Anyway I forgot to post an update here, but the reason why I've left this branch for a while is because this upgrade isn't giving us better filesizes or build times (better in dev, worse in prod), so all in all it looks like a regression. I'm sure we're doing something wrong, but I can't figure out where - probably because we're not using OptimizeCSSAssetsPlugin, but like I said before it's not playing well with sourcemaps

Copy link
Member

@li-kai li-kai left a comment

Choose a reason for hiding this comment

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

LGTM 🗳

'default',
{
// mergeLonghand produces incorrect transformations with border
// https://github.com/cssnano/cssnano/issues/557
Copy link
Member

Choose a reason for hiding this comment

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

This was fixed!

@@ -10,3 +10,21 @@ module.exports = {
require('./scripts/postcss-single-root'),
],
};

// Use CSSNano in production
if (process.env.NODE_ENV === 'production') {
Copy link
Member

Choose a reason for hiding this comment

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

Should we run this in dev too? It's easier to identify errors that way.

Copy link
Member Author

Choose a reason for hiding this comment

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

May slow it down though. I don't know what's the overhead but I assume it's not nothing

@@ -45,8 +41,6 @@ const VENDOR = [
'history', // History module used by router
'fbjs', // facebook deps
'prop-types', // gone but not forgotten
'loader', // style loader fallbacks
'equal', // various comparison libs used by deps
];

const DLL = {
Copy link
Member

Choose a reason for hiding this comment

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

We can drop this now we don't have dll.

const extractTextPlugin = new ExtractTextPlugin('[name].[chunkhash].css', {
allChunks: true,
const cssExtractPlugin = new MiniCssExtractPlugin({
filename: '[name].[chunkhash:8].css',
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

@ZhangYiJiang ZhangYiJiang Aug 29, 2018

Choose a reason for hiding this comment

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

I don't think that's right? Article says content hash is from ExtractTextPlugin which doesn't exist anymore

Copy link
Member

Choose a reason for hiding this comment

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

It's replaced by MiniCssExtractPlugin, which should work the same way

@ZhangYiJiang
Copy link
Member Author

I'm still hesitant about merging this in. Currently

  • Build size is slightly bigger (5kb) and split into more files. More files is probably not a problem, and 5kb is pretty negligible, but it is no better than before
  • Dev times (both hot and cold) are comparable as far as I can tell
  • CI build times are significantly slower (1.47 vs. 2.49). There will be some variance due to CI resources, but this is pretty bad - it's about 50% more.

@ZhangYiJiang
Copy link
Member Author

  • Removed lint phase from prod build as suggested by @liaujianjie (thanks!) - this is acceptable because in CI lint is already done separately, so this is just redundant
  • UglifyWebpackPlugin -> TerserWebpackPlugin - uglify-es was forked since the original maintainer abandoned it

I think the branch is ready to merge now. Just need to run through the usual checks to make sure upgrading the build toolchain didn't break anything

@ZhangYiJiang
Copy link
Member Author

ZhangYiJiang commented Oct 23, 2018

Remaining issues (non-blockers)

  • FlowStatusWebpackPlugin is not updated, so you get a DeprecationNotice. The plugin looks unmaintained, but it should be easy to use a fork which fixes the issue
  • Babel optimize-react-preset is not updated, and also looks unmaintained. A preset is just a function that returns a bunch of plugins though, so it's easy to fix this too.

@ZhangYiJiang ZhangYiJiang merged commit e9b8f7d into master Oct 24, 2018
@ZhangYiJiang ZhangYiJiang deleted the webpack-4.1 branch October 24, 2018 06:22
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.

4 participants