You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently we set the NODE_ENV by mapping 1:1 to our Webpack configs. When working with multiple environments (e.g. dev, staging, dist) I found the requirement for finer control. E.g. to achieve this
In this example, staging and dist should both build with production optimizations (e.g. webpack -p and NODE_ENV=production). However, staging may differ in other conditional flags used throughout the app. This means, inside the project I need to distinguish between code targeted for staging and production, which I do by means of the APP_ENV setting.
Initially I was using the setting from src/config/<env>.js to pick appropriate values. However, in the case of dynamic requires Webpack would not eliminate dead code that way, so I'd propose using the DefinePlugin and introduce two changes to the configs:
This way, process.env.APP_ENV becomes available in code and everything inside the branch will be eliminated from the bundle size when the condition is not met (I am using it for things like requiring gobal mocks, adding dev routes, dev components, etc.).
Hi @sthzg, more than ok. I use it nearly the same way in some current projects where I use the global conf to set api url targets for dev, staging and production usage. Currently, I just copied the base dev config and adjusted it accordingly (which was way harder when using v2 of the generator). For me this is totally fine.
Currently we set the
NODE_ENV
by mapping 1:1 to our Webpack configs. When working with multiple environments (e.g.dev
,staging
,dist
) I found the requirement for finer control. E.g. to achieve thisIn this example,
staging
anddist
should both build with production optimizations (e.g. webpack -p and NODE_ENV=production). However,staging
may differ in other conditional flags used throughout the app. This means, inside the project I need to distinguish between code targeted for staging and production, which I do by means of theAPP_ENV
setting.Initially I was using the setting from
src/config/<env>.js
to pick appropriate values. However, in the case of dynamic requires Webpack would not eliminate dead code that way, so I'd propose using theDefinePlugin
and introduce two changes to the configs:This way,
process.env.APP_ENV
becomes available in code and everything inside the branch will be eliminated from the bundle size when the condition is not met (I am using it for things like requiring gobal mocks, adding dev routes, dev components, etc.).@weblogixx would this addition be okay for you?
The text was updated successfully, but these errors were encountered: