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
I'm working on a network of sites where we want to include different config for each property, where the property is identified by an environment variable.
That means we have a config file that looks like this:
if (process.env.SITE_KEY === 'site1') {
module.exports = require('./site1');
} else if (process.env.SITE_KEY === 'site2') {
module.exports = require('./site2');
}
Any other module that wants to know something in the site config requires this one.
The problem is that all site configs are bundled into each site's build, even though only the active one is used. Not really a huge issue, but it's not a clean solution either.
It seems like it might be possible to hook envify into the browserify pipeline in a way that replaces environment variables before require statements are evaluated, which would allow the following:
@JedWatson envify does indeed get applied before browserify looks for require statements! I think it should work using require('./' + process.env.SITE_KEY) but gotta try and see :)
Just following a thread here, not sure if it's possible or not.
As noted in browserify/browserify#377 browserify uses static analysis to figure out what to build.
I'm working on a network of sites where we want to include different config for each property, where the property is identified by an environment variable.
That means we have a config file that looks like this:
Any other module that wants to know something in the site config requires this one.
The problem is that all site configs are bundled into each site's build, even though only the active one is used. Not really a huge issue, but it's not a clean solution either.
It seems like it might be possible to hook
envify
into the browserify pipeline in a way that replaces environment variables before require statements are evaluated, which would allow the following:If we could rewrite that with envify before browserify goes looking for
require
statements, it would see:Any ideas on whether that's possible / feasible? Or do you know of any other ways to achieve this? I went looking but didn't find anything.
The text was updated successfully, but these errors were encountered: