-
Notifications
You must be signed in to change notification settings - Fork 59
react-app-rewire-define-plugin equivalent #4
Comments
Hi @saostad –– absolutely. You can install
module.exports = [
[
'use-rewire',
'react-app-rewire-define-plugin',
process.env.NODE_ENV,
{
'process.env.VERSION': JSON.stringify(require('./package.json').version)
}
]
] Although I'd recommend doing this instead:
const {appendWebpackPlugin} = require('@rescripts/utilities')
const {DefinePlugin} = require('webpack')
module.exports = config =>
appendWebpackPlugin(new DefinePlugin({
'process.env.VERSION': JSON.stringify(require('./package.json').version)
}), config) ^ that should do the trick. Please let me know if you encounter any problems. If this solves your problem, please close the issue 👍 & thanks for using Rescripts! Let me know anything I can do to make it a better developer experience for you! |
thanks for quick response.
|
@saostad it depends where you need the reference. I don't think you'd need the |
what I wanna do is just run build or start command but because I have 2 different API url for dev and prod environments I wanna define one global variable (API_URL) and in build time set it based on the environment. |
@saostad then you'll probably want to do something similar to what you had above: const { appendWebpackPlugin } = require("@rescripts/utilities");
const { DefinePlugin } = require("webpack");
const { NODE_ENV, API_PROD_URL, API_DEV_URL } = process.env
const API_URL = NODE_ENV === 'production' ? API_PROD_URL : API_DEV_URL
module.exports = config =>
appendWebpackPlugin(
new DefinePlugin({ API_URL }),
config,
); Also, const { appendWebpackPlugin } = require("@rescripts/utilities");
const { DefinePlugin } = require("webpack");
const { NODE_ENV, API_PROD_URL, API_DEV_URL } = process.env
const API_URL = NODE_ENV === 'production' ? API_PROD_URL : API_DEV_URL
module.exports = appendWebpackPlugin(
new DefinePlugin({ API_URL }),
); Please let me know if this was helpful (and if so, please close the issue) 👍 |
this is the only way it works for me:
for some reason I still need to do |
@saostad ohhh––you're passing the environment vars through a .env file, not as script params... in that case, using |
Correct! |
I have created a repo in case anybody wants to see the solution |
Hi,
is there any way to define environment variable in webpack config?
something like :
The text was updated successfully, but these errors were encountered: