@AquiGorka did you figure out a way around this?
@kirakik I did not and in the end used create-react-app which has built-in support for env vars.
In your nwb.config.js file, use the extra option to add webpack's environment plugin:
const webpack = require("webpack");
module.exports = {
type: "react-component",
npm: {
esModules: true,
umd: {
global: "SomeApp",
externals: {
react: "React"
}
}
},
webpack: {
extra: {
plugins: [
new webpack.EnvironmentPlugin({
BLAH: "aha"
})
]
}
}
};
In the above example, access it as process.env.BLAH
You should be able to have dynamic env vars if you do
process.env.NODE_ENV === 'production' ? {secretKey: '....'} : {}
Reference:
https://github.com/insin/nwb/blob/master/docs/Configuration.md#extra-object
If you wanted to use dotenv, you could also use it like so (untested):
import dotenv from 'dotenv';
/* etc */
new webpack.EnvironmentPlugin({
...dotenv.config().parsed
}),
Or checkout the dotenv webpack plugin:
https://github.com/mrsteele/dotenv-webpack
Most helpful comment
In your
nwb.config.jsfile, use theextraoption to add webpack's environment plugin:In the above example, access it as
process.env.BLAHYou should be able to have dynamic env vars if you do
Reference:
https://github.com/insin/nwb/blob/master/docs/Configuration.md#extra-object
If you wanted to use
dotenv, you could also use it like so (untested):Or checkout the
dotenvwebpack plugin:https://github.com/mrsteele/dotenv-webpack