-
Notifications
You must be signed in to change notification settings - Fork 108
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
Upgrading Webpack to v4.5, enable caching via the uglifyJS, and modifying output #3970
Conversation
@@ -60,27 +60,36 @@ const COMMON_CHUNK_CONFIG = new webpack.optimize.SplitChunksPlugin( { | |||
name: COMMON_BUNDLE_NAME | |||
} ); | |||
|
|||
const STATS_CONFIG = { | |||
stats: { | |||
entrypoints: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is such a short config, what do you think about putting the false
value in a constant and then putting the rest in each webpack object? This would make the object spread unnecessary and simplify the webpack configs that aren't using multiple copies of STATS_CONFIG
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it as an separate object because it can be extended when debugging and you don't have to update things in multiple places. This is the entire list of stat options: https://webpack.js.org/configuration/stats/#stats
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah gotcha, I didn't realize there were so many settings in there. One thing I'm confused on is https://webpack.js.org/configuration/stats/#stats shows entrypoints: false
like that's the default value. What's the default state of the stats object in the config? Is the default that it's absent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I'm not sure what the default values are and the string value doesn't work with Webpack stream. shama/webpack-stream#163.
@@ -9,7 +9,7 @@ parserOptions: | |||
globalReturn: false | |||
impliedStrict: true | |||
jsx: true | |||
experimentalObjectRestSpread: false | |||
experimentalObjectRestSpread: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need an update in https://github.com/cfpb/development/blob/master/.eslintrc#L12 (and CF and generator-cf)? This is to avoid usage of Object.assign
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's my understanding that object rest spread has reached stage 4 per: https://github.com/tc39/proposal-object-rest-spread. I think its easier to read and less code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me! We should adjust the other eslints to match I'd say, so https://github.com/cfpb/development/blob/master/.eslintrc#L12 and https://github.com/cfpb/capital-framework/blob/canary/.eslintrc#L12
@@ -37,14 +38,19 @@ const COMMON_MODULE_CONFIG = { | |||
presets: [ [ 'babel-preset-env', { | |||
targets: { | |||
browsers: BROWSER_LIST.LAST_2_IE_9_UP | |||
}, | |||
debug: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be inclined to leave this as debug: false
so it's easier to find where to turn it on, like is done with the uglify config. Or do you think that's too much clutter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in cc2efa0.
module: COMMON_MODULE_CONFIG, | ||
mode: 'production', | ||
output: { | ||
filename: 'spanish.js' | ||
}, | ||
plugins: [ | ||
COMMON_UGLIFY_CONFIG | ||
] | ||
], | ||
...STATS_CONFIG |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is the only webpack config where the STATS_CONFIG
is used multiple times, you could modify the loop at the end of the file:
let currConfig;
for ( const key in configExports ) {
currConfig = configExports[key];
currConfig.stats = STATS_CONFIG.stats; // Or use Object.assign(…)
if ( NODE_ENV === 'development' ) {
// eslint-disable-next-line guard-for-in
Object.assign( currConfig, devConf );
}
}
That would render the need for turning on the experimental flag unnecessary.
Or alternatively, the object spread could be used for mixing in the dev config as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we have to use object spread or Object.assign uniformly in all cases. I think the code reads wells as it is. There might be a case for using the object spread for COMMON_MODULE_CONFIG
though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
How is the cache expired with it turned on here? Do we need to do anything in our |
It's my understanding that the cache will automatically be invalidated upon files changing. This the default config for webpack per: webpack-contrib/uglifyjs-webpack-plugin#224 (comment). |
3d1e08d
to
cc2efa0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works as described!
Upgrading Webpack to v4.5, enable caching via the uglifyJS Plugin, and modifying Webpack output
Changes
Testing
Example:
Entrypoint Expandable.js = Expandable.js
open node_modules/.cache/uglifyjs-webpack-plugin
and verify that the folder exists.Notes
Checklist
Testing checklist
Browsers
Accessibility
Other