Build Toggles
It is common to switch in JavaScript projects based on where they are being run. You can do this quite easily with webpack as it supports dead code elimination based on environment variables.
Add different targets in your package.json
scripts
:
Of course I am assuming you have npm install webpack --save-dev
. Now you can run npm run build:test
etc.
Using this variable is super easy as well:
We use
process.env.NODE_ENV
just because it is conventional in a lot of JavaScript libraries themselves e.g.React
.
Last updated