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.

Craco generated config API

See original GitHub issue

Have you considered exposing an API that will return the merged config for the various portions of the react-scripts build process? That way people can use them in other places of their app and remain in sync with their actual build process.

The reason I ask is because I use vscode-jest, which I really like because it runs your tests in real time. However, it doesn’t know how to use react-scripts jest config, so you have to tell it how. I did that by creating my own jest.config.js. I wanted it to run the exact same way that it would if I run craco test, though, and I didn’t want to reinvent the wheel. I also wanted to reduce the time I would have to spend maintaining configurations for craco and for vscode-jest

So, I wound up digging through craco and react-scripts to find what I needed, and put it all together so that the end result would be my craco generated react-scripts jest config. You can see the working product here:

https://gist.github.com/Js-Brecht/84ad06ac851af23ea84829fac4dd4fe2

As you can see, it starts out as basically a copy of test.js, then kind of pretends to be react-scripts.

Configured this way, I can make changes in one place, craco.config.js, and see the results in vscode immediately. The behavior is also identical between live & build processes. It’s great.

BUT, I am pretty much locked into one version of both react-scripts, and craco. If I upgrade, I would then have to spend time maintaining this config, to keep it up to date with the two repositories. I’m essentially banking on those processes not changing much in the future.

It would be great to just call a function from craco to get the generated configuration, and use that. Then, if I wanted to add some functionality that’s separate from the build process, I could do that, too; plus I wouldn’t have to hook into modules that are probably supposed to be internal 😕

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
Js-Brechtcommented, Aug 13, 2019

It works great! Much simpler 🙂. I don’t have occasion to use the Webpack API, but I can confirm that the Jest API works.

1reaction
patricklafrancecommented, Aug 12, 2019

Hi @Js-Brecht

The API is available with 5.3.

Documentation is available here.

I would love to have your feedback!

Patrick

Read more comments on GitHub >

github_iconTop Results From Across the Web

craco/README.md at main - GitHub
Create React App Configuration Override, an easy and comprehensible configuration layer for create-react-app. Find config docs, API docs, plugins, and example ...
Read more >
5.8.0 - @craco/craco - npm
Create React App Configuration Override, an easy and comprehensible configuration layer for create-react-app.. Latest version: 7.0.0, ...
Read more >
Using Create-React-App + Craco + Typescript to build apps ...
One of the best things about React is create-react-app, a CLI tool for setting up and maintaining a react project. With create-react-app it...
Read more >
@craco/craco NPM | npm.io
The current API support Jest and Webpack. Jest API. Accept a cracoConfig , a context object and options . The generated Jest config...
Read more >
Advanced Configuration - Create React App
Variable Development Production BROWSER ✓ Used 🚫 Ignored BROWSER_ARGS ✓ Used 🚫 Ignored HOST ✓ Used 🚫 Ignored
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