Static config file at project root
See original GitHub issueAfter searching through the issues I can’t seem to find anyone asking this, but if I have missed it please link me to it.
I know CRA has the concept of env variables but I am looking for a little more than this (I want to include objects and arrays). I want to have a config
directory in the root of my project, and inside an index.js
something like:
import local from './local';
import global from './global';
const env = require(`./${process.env.NODE_ENV}`);
export default { ...global, ...env.default, ...local };
This will give me a config file for each environment but also a local.js
where I can override anything I need, for example during development I want to change an API_URL
to a local branch.
My question is using CRA can I get webpack to recognize this file outside of the src
directory? I don’t want to have to eject just to add some static config files.
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
How to manage static files (e.g. images, JavaScript, CSS)
Store your static files in a folder called static in your app. For example my_app/static/my_app/example.jpg . Serving the files. In addition to these ......
Read more >Is there a way to put every configuration file to a config ...
1. Use IDE settings to hide config files. I recommend that you keep them in their default location since it is a common...
Read more >The creeping scourge of tooling config files in project root ...
I don't get this, what's the problem here? Having config files in root means you know they can apply to all sub directories....
Read more >Static files in ASP.NET Core | Microsoft Learn
Static files are stored within the project's web root directory. The default directory is {content root}/wwwroot , but it can be changed ...
Read more >Config Files - Babel.js
For project-wide configuration, Babel will automatically search for a babel.config.json file, or an equivalent one using the supported extensions, in this root ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For anyone finding this issue, a working solution has been to have a
config
folder at the project root, inside I haveproduction.js
anddevelopment.js
, each file looks something like:I then have a
index.js
:And then in code I have just
import
this file and get the values egconfig.key
@gaearon With the 1.0 updates the method listed above (https://github.com/facebookincubator/create-react-app/issues/1469#issuecomment-290081143) breaks due to the config file being outside
src
.What do you suggest now? I don’t think pulling the
config
folder intosrc
makes sense, so would be interested to hear how you’d solve this issue.