-
-
Notifications
You must be signed in to change notification settings - Fork 27k
Reorganize webpack configuration structure #7450
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
base: main
Are you sure you want to change the base?
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
@@ -412,5 +412,5 @@ Returns a cache identifier (string) consisting of the specified environment and | |||
```js | |||
var getCacheIdentifier = require('react-dev-utils/getCacheIdentifier'); | |||
|
|||
getCacheIdentifier('prod', ['react-dev-utils', 'chalk']); // # => 'prod:[email protected]:[email protected]' | |||
getCacheIdentifier('production', ['react-dev-utils', 'chalk']); // # => 'prod:[email protected]:[email protected]' |
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 updated this because current usage of this function inside of webpack config(s) was "development" or "production".
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.
Don't forget to update the comment too.
58c1828
to
94f91ab
Compare
f626d4d
to
5ff14ae
Compare
} | ||
) | ||
), | ||
new webpack.ProgressPlugin(), |
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.
There's been lots of discussion in the past about different progress plugin issues (inaccuracy, slowness) (eg. back in #1011, last time in #6310 (comment)). How's the current state of the webpack.ProgressPlugin
compared to those old solutions?
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 know what versions of webpack these comments where in context to, however we have made a few enhancements and fixes over webpack 2 and 3. cc @sokra for his comments.
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.
The lastest version has some fixes and ProgressPlugin should have very small impact.
see also webpack/webpack#9466
@@ -412,5 +412,5 @@ Returns a cache identifier (string) consisting of the specified environment and | |||
```js | |||
var getCacheIdentifier = require('react-dev-utils/getCacheIdentifier'); | |||
|
|||
getCacheIdentifier('prod', ['react-dev-utils', 'chalk']); // # => 'prod:[email protected]:[email protected]' | |||
getCacheIdentifier('production', ['react-dev-utils', 'chalk']); // # => 'prod:[email protected]:[email protected]' |
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.
Don't forget to update the comment too.
}, | ||
plugins: [ | ||
new HtmlWebpackPlugin( | ||
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.
Is this Object.assign
necessary?
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.
If they are separated now I don't think so. Looks like it was more necessary when they were combined with the ternary.
mode, | ||
// https://webpack.js.org/configuartion/output | ||
output: { | ||
// TODO: remove this when upgrading to webpack 5 |
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 comment applies to the futureEmitAssets
flag on the next line.
// This is necessary to emit hot updates (currently CSS only): | ||
new webpack.HotModuleReplacementPlugin(), | ||
// See https://github.com/facebook/create-react-app/issues/240 | ||
new CaseSensitivePathsPlugin(), |
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 looks like a duplicate (see line 51)
// See https://github.com/facebook/create-react-app/issues/240 | ||
new CaseSensitivePathsPlugin(), | ||
// See https://github.com/facebook/create-react-app/issues/186 | ||
new WatchMissingNodeModulesPlugin(paths.appNodeModules), |
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.
Dupe here as well
Do you mind signing the CLA @TheLarkInn? :) |
This is amazing, thanks @TheLarkInn. |
// https://webpack.js.org/configuartion/optimization | ||
optimization: { | ||
splitChunks: { | ||
name: 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.
chunks: "all"
should be kept. It allows to vendor split the main chunk
// We are in the development config. This contains development only features. | ||
module.exports = function() { | ||
return { | ||
devtool: 'cheap-module-source-map', |
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.
eval-cheap-module-source-map
would be faster
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.
We had an issue when we switched to eval-source-map due to mismatch line numbers in react-error-overlay. I don't remember whether I tried eval-cheap-module-source-map.
See webpack/webpack#8910
} | ||
) | ||
), | ||
new webpack.ProgressPlugin(), |
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.
The lastest version has some fixes and ProgressPlugin should have very small impact.
see also webpack/webpack#9466
// See https://github.com/facebook/create-react-app/issues/186 | ||
new WatchMissingNodeModulesPlugin(paths.appNodeModules), | ||
// This is necessary to emit hot updates (currently CSS only): | ||
new webpack.HotModuleReplacementPlugin(), |
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.
duplicate
// By default we support CSS Modules with the extension .module.css | ||
{ | ||
test: cssRegex, | ||
exclude: cssModuleRegex, |
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 exclude
could be omitted when this rule is switched with the next rule.
// extensions .module.scss or .module.sass | ||
{ | ||
test: sassRegex, | ||
exclude: sassModuleRegex, |
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.
Same. Switch with the next rule.
@TheLarkInn, we'd love to get this in - we're thinking 3.3. Are you able to take a look at the suggestions/requested changes? |
At this point, I gave up fixing the merge conflict since it happens in the entire file at once. Unless you want @TheLarkInn to be the person moving forward with this, I can fix the merge conflict and continue with the task. I fixed all the requested changes. |
This PR Kicks off the process of reorganizing the current webpack configuration for CRA. We at webpack want to give first time webpack user's the best possible experience. This demographic includes developers who would eject CRA to experiment, learn, extend possibly for the first time.
We think the current config format has a lot of opportunities for organization. That being said:
Changes in this PR
webpack.ProgressPlugin()
for development environmentchunks:'all'
optimization which is only relevant for Multipage App Architectures