Skip to content

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

TheLarkInn
Copy link

@TheLarkInn TheLarkInn commented Jul 29, 2019

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

  • Create development and production config containing their environment specific configuration details.
  • Separate module from the base webpack config and isolate to a separate file for manageability.
  • Add webpack-merge as a dependency to safely compose prod and dev configs with base config
  • Remove some defaulted configuration values already set for specific env's.
  • Add webpack.ProgressPlugin() for development environment
  • Remove chunks:'all' optimization which is only relevant for Multipage App Architectures
  • Any time a CRA Issue was mentioned in comments, I removed prepended commentary (for the sake of readability.)

@facebook-github-bot
Copy link

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]'
Copy link
Author

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".

Copy link
Contributor

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.

@TheLarkInn TheLarkInn force-pushed the feature/organize-config branch from 58c1828 to 94f91ab Compare July 29, 2019 19:45
@TheLarkInn TheLarkInn force-pushed the feature/organize-config branch from f626d4d to 5ff14ae Compare July 29, 2019 19:53
@bugzpodder bugzpodder added this to the 3.2 milestone Jul 29, 2019
}
)
),
new webpack.ProgressPlugin(),
Copy link
Contributor

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?

Copy link
Author

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.

Copy link

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]'
Copy link
Contributor

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(
Copy link
Contributor

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?

Copy link
Author

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
Copy link
Contributor

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(),
Copy link
Contributor

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),
Copy link
Contributor

Choose a reason for hiding this comment

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

Dupe here as well

@ianschmitz
Copy link
Contributor

Do you mind signing the CLA @TheLarkInn? :)

@mrmckeb
Copy link
Contributor

mrmckeb commented Aug 1, 2019

This is amazing, thanks @TheLarkInn.

// https://webpack.js.org/configuartion/optimization
optimization: {
splitChunks: {
name: false,
Copy link

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',
Copy link

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

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(),
Copy link

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(),
Copy link

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,
Copy link

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,
Copy link

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.

@mrmckeb
Copy link
Contributor

mrmckeb commented Oct 16, 2019

@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?

@yordis
Copy link

yordis commented Oct 16, 2019

@mrmckeb #7638 ...

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.

@ianschmitz ianschmitz modified the milestones: 3.3, 3.4 Dec 5, 2019
@iansu iansu modified the milestones: 3.4, 3.5 Feb 14, 2020
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.

10 participants