I am trying to do something like this
// config.js
var path = require("path"),
env = process.env.NODE_ENV || "fail";
module.exports = require(path.join(__dirname, env));
Some file that uses the config
// app.js
var config = require("./config");
console.log(config);
And bundle with this command
NODE_ENV=test browserify -d app.js > public/test/app.js
Browserify is not picking up the NODE_ENV assignment and it's trying to include fail environment when I run my testing bundle :frowning:
Uncaught Error: Cannot find module '/config/fail'
browserify doesn't work with conditional requires and can't be made to work with arbitrary dynamic requires without solving the halting problem first. Do something different instead. This is a dead end.
:flushed: a response from the master!
Thank you for such a pragmatic response. I'll do a little more research and see what other things I can do to solve the problem.
@naomik have a look at the browser-field to load different modules in the browser than in node.
If you need more power, i.e. swap out modules for different environments browserify-swap may help you, but you gotta have a real good reason to do that (kinda hacky).
Usually dynamic dependencies are not necessary :smile:
Most helpful comment
Usually dynamic dependencies are not necessary :smile: