How To Create/generate/export A File From My Webpack 2 Config To Be Used Inside Of My React Code?
I am passing in NODE_ENV variables into my webpack.config from package.json in order to return an object that either contains API endpoints for localhost or production. 1) package.
Solution 1:
I think this is an XY problem. You could generate the files with a bit of Node (something like fs.writeFileSync('api.js', contents)
, or you could do it with a bit of shell scripting, but you could also just use env
in your code using DefinePlugin (example: new webpack.DefinePlugin({ env: JSON.stringify(process.env.NODE_ENV) })
. Then you'd be able to access env
in your code directly.
Post a Comment for "How To Create/generate/export A File From My Webpack 2 Config To Be Used Inside Of My React Code?"