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: Allow extension of configurations

See original GitHub issue

Hey there! I was recently thinking about a way to keep cra zero-config to begin with but also allow it to grow/override if/when needed (css-modules, typescript, lqip, etc etc)

My proposal would be to have a file at root level called react-scripts.config.js in which the template would look a bit like this:

module.exports = {
  devConfig: (config, webpack) => config,
  productionConfig: (config, webpack) => config,
  serverConfig: (config, webpack) => config,
}

In all of those cases they would take a function with the first argument being the opinionated config from cra and a second optional argument which would be the same webpack used for whatever script being used (for plugins or whatever)

So now the user can tweak that config or even make another one remembering that in the end he has to return a config object for webpack to consume.

Now on the scripts code we can run fs.existsFileSync to check for that file and then to check if the object has that prop which we care for depending on the case. Eg. on start script check for either devConfig or serverConfig

So now we can do something like:

  // react-scripts/scripts/start.js for example
  // defaultConfig would be the one living on `react-scripts/config/webpack.config.dev.js for example

  const userConfig = path.join(process.cwd(), ('react-scripts.config.js'))
  const hasCustomConfig = existsSync(userConfig) && require(userConfig).devConfig
  const config = hasCustomConfig
    ? require(userConfig).devConfig(defaultConfig, webpack)
    : defaultConfig
  // rest of normal code

This would make it still be zero-config, but extendable. That way users don’t have to choose between no freedom or all the freedom, but rather get the right amount of freedom without losing on updates or forking the package.

Does this has potential? lmk and i could work on a PR to make this happen i don’t think its a really big change on the codebase to achieve.

Cheers and thanks to everyone for this awesome package. ❤️

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
AndyOGocommented, Sep 21, 2018

Hi, why not getting inspired by Next.js success?

1reaction
shelldandycommented, Jun 13, 2018

Yeah I use that as well quite often (I’m using it right now), but then again wouldn’t it be much better to have that “composability” from a first-party source?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Proposed API - Visual Studio Code
These are the steps for testing a proposed API in local extension development: Use Insiders release of VS Code. To your package.json ,...
Read more >
Configure ExtensionSettings policy - Chrome Enterprise and ...
The ExtensionSettings policy controls multiple settings, ... Specifies what types of app or extension users are allowed to install on Chrome Browser.
Read more >
Allow Extensions To Contribute Language Specific Settings
Proposals. Allow extensions to mark settings as being valid language specific settings. Add apis for better working with language specific settings.
Read more >
User Guide for Cisco Security Manager 4.20 - Easy VPN [Cisco ...
Easy VPN can be configured in three modes—Client, Network Extension, and Network Extension Plus. Client mode—The default configuration that allows devices ...
Read more >
SAP Cloud for Customer Extension Guide
This document describes all functions that you can accesse as an administrator using the Start Adaptation.
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