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.

Add environment variables to manifest.json files

See original GitHub issue

Is your proposal related to a problem?

In the application, we have several places where we put the values that are in the manifest file, like the theme color, the app name, etc. Unfortunately, if we need to change them one day, we would need to do it everywhere we use them.

Describe the solution you’d like

It would be of very good use if we were able to insert those names in an environment variable file, such as .env, and use it in the manifest.json as well, just like we do in the index.html file.

{
  "short_name": "%REACT_APP_SHORT_NAME%",
  "name": "%REACT_APP_NAME%"
}

Describe alternatives you’ve considered

The only solution to have it automatic would be to or eject the configuration and apply the JSON files to the compilation files, or to add another compilation script that would run during the build process.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:83
  • Comments:15

github_iconTop GitHub Comments

13reactions
paulmwatsoncommented, May 28, 2020

@Marian0 In webpack.config.js I used CopyPlugin which has a transform method that you can do string replacements on. e.g.

module.exports = {
...
  plugins: [
    new CopyPlugin([
      {
        from: 'manifest.json',
        transform(content, path) {
          return content
            .toString()
            .replace(
              'process.env.API_BASE_URL',
              process.env.API_BASE_URL
            )
        },
      },
...

This works in dev and builds.

12reactions
bkeatingcommented, Jul 13, 2020

Would love to env var support build into CRA for any/all(?) public dir files.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Environment variables in manifest.json - Chrome Extension
In my case, I needed to set version automatically on manifest file. I added to webpack script: plugins: [ new CopyWebpackPlugin([ { from:...
Read more >
Environment variables in manifest.json - Chrome Extension ...
Here's how you do it: Install craco into your project using npm i @craco/craco . Install copy-webpack-plugin as a dev-dependency in your project...
Read more >
App Manifest Attribute Reference | Cloud Foundry Docs
Create a file called vars.yml . · Add attributes to your vars.yml file. For example: · Add the variables to your app manifest...
Read more >
Creating environment variable from JSON file
You could write some PHP at the top of your general.php file that reads the JSON manifest in your public root directory, and...
Read more >
Additional folders needed for path when running build ...
Build error: env: node: No such file or directory Path was: ... desktop app currently doesn't set the PATH environment variable correctly”.
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