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.

react-app-rewire-define-plugin

See original GitHub issue

Hi,

is there any way to define environment variable in webpack config? something like :

const rewireDefinePlugin = require('react-app-rewire-define-plugin')

// Use `webpack.DefinePlugin` to add the version number from package.json
config = rewireDefinePlugin(config, env, {
  'process.env.VERSION': JSON.stringify(require('./package.json').version)
})

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8

github_iconTop GitHub Comments

15reactions
aaronchenweicommented, Jan 9, 2019

Here is what we tried to rewire process.env


const findWebpackPlugin = (plugins, pluginName) =>
  plugins.find(plugin => plugin.constructor.name === pluginName);

const overrideProcessEnv = value => config => {
  const plugin = findWebpackPlugin(config.plugins, 'DefinePlugin');
  const processEnv = plugin.definitions['process.env'] || {};

  plugin.definitions['process.env'] = {
    ...processEnv,
    ...value,
  };

  return config;
};

module.exports = override(
  overrideProcessEnv({
    VERSION: JSON.stringify(require('./package.json').version),
  })
);
0reactions
foxundermooncommented, Jan 1, 2020

https://github.com/foxundermoon/cra-define-override#readme

npm i -D cra-define-override
// config-overrides.js
const { overridePassedProcessEnv } = require("cra-define-override");

module.exports = override(
  overridePassedProcessEnv(["BASE_URL", "OTHER_ENV_NAME"])
);

then

BASE_URL=https://fox.mn   npm run build
Read more comments on GitHub >

github_iconTop Results From Across the Web

react-app-rewire-define-plugin - npm
DefinePlugin to a react-app-rewired config. ... Start using react-app-rewire-define-plugin in your project by running `npm i ...
Read more >
react-app-rewire-define-plugin | npm trends
Comparing trends for react-app-rewire-define-plugin 1.0.0 which has 606 weekly downloads and unknown number of GitHub stars.
Read more >
Add webpack plugins through config-overrides.js
I'm using react app with customized configuration without ejecting and for that I'm using react-app-rewire. To provide plugins to webpack, ...
Read more >
react-app-rewired | Yarn - Package Manager
react -app-rewired. owner timarney1.7mMIT2.2.1 vulns 0 vulnerabilities. Tweak the create-react-app webpack config(s) without using 'eject' and without ...
Read more >
How create-react-app fakes environment variables
We can see it used later when create-react-app sets up its webpack config: The Webpack DefinePlugin is being passed this object containing our ......
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