question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Proposal] Consider composing webpack config

See original GitHub issue

This is a continuation of this comment https://github.com/facebookincubator/create-react-app/pull/1651#issuecomment-305188047 and maybe related to https://github.com/facebookincubator/create-react-app/issues/670 (but for internal use only) and I want to see a discussion about this implementation.

For a past few months I’ve been working on PRs and watching this repo, and a lot of the PR and issues are about adding something to the webpack config. I thought to myself, how can we add something to it without making it more complex?

And then I read this articles reading https://medium.com/making-internets/webpack-configuration-done-right-86c325a6927f ,

I’ve been thinking maybe we should have an INTERNAL hook/middleware for composing webpack config.

Right now AFAIK we have 3 three separate PR working on adding something to webpack config, 2 of them is optional (DLL and commonsChunk) and one is CSS module (which the user can opt it out if they use CSS in JS solution).

And for the merged ones, SWPrecache is an optional feature but we still have the webpack plugins installed, even when the user is not using it.

I think we could go with something like

const compose = require('promise-compose');
const webpackAutoDllCompiler = options => config => new Promise(resolve =>
 if (dllSrcExists()){ // only modify the config if `src/index.dll.js` exists
  config.plugins = config.plugins.concat([new webpackDllCompiler(options)]) // simplified for example purpose
  //compile it
  webpack().run(() => resolve(config))
 }
 //don't waste resource on optional feature
 resolve(config)
)
const configComposer = compose(
  webpackAutoDllCompiler({
    dllConfig,
    paths,
  }), //config resolver for dll feature
  webpackPWAConfigResolver(), //config resolver for anything related to PWA feature
  webpackCSSModuleConfigResolver(), //config resolver for CSS Module
);


//somewhere in start.js
const config = require('barebone/config/without/additional/features')
webpack(configComposer(config))

The config resolvers could be placed in react-dev-utils or config/resolvers, so additional features are neatly placed in their own modules and called when needed.

I know maybe this would make the codebase harder to follow because the configuration is hidden in the resolvers, but it would make CRA more modular. if the ejected users wanted more config / disabling a feature, they can comment out the call in the configComposer and do the configuration themselves. This way trying out new features is just a matter of adding a new line in the compose function, and no resource wasted for unused features. And because it’s internal, we can control how the resolver plays with each other (plugin ordering issue, the shape of loaders section config etc). Thoughts?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
gaearoncommented, Jun 22, 2017

if the ejected users wanted more config / disabling a feature, they can comment out the call in the configComposer and do the configuration themselves

I don’t think this is an acceptable tradeoff. It’s hard enough to deal with Webpack configuration, and I feel like obscuring it behind a call will make it even harder for people who eject. For many users (especially new to JS), “call this function and inline the result” when they need to change something is pretty much insurmountable.

0reactions
gaearoncommented, Jun 22, 2017

Yes, pretty much that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Concepts - webpack
Since version 4.0.0, webpack does not require a configuration file to bundle your project. Nevertheless, it is incredibly configurable to better fit your ......
Read more >
Writing a custom webpack loader - Redd Developer
There are two ways to use a loader: tell webpack to resolve it from a local file, or publish it and install as...
Read more >
Writing Webpack Loader - Gleb Bahmutov
In this blog post I will show how to write a Webpack loader. We will load Markdown files, will find a JavaScript code...
Read more >
Loader changes proposal · Issue #2975 · webpack ... - GitHub
This is a proposal for some new features for the loader API. Motivation: typescript loaders need more than the normal loader API and...
Read more >
An Annotated webpack 4 Config for Frontend Web…
Please consider sponsoring me to keep writing articles like this. ... The premise is amazing, building a webpack config by snapping ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found