Closed erikhuisman closed 8 years ago
I did something like this to load some environment variables. Might come in handy to people building for test, staging, production.
if (options.env) { var envfile = path.join(process.cwd(), path.dirname(entry), '.env.js') try { var environments = require(envfile); config.plugins.push(new webpack.DefinePlugin(environments)) config._msgs.push(util.format( 'Using custom environments (%s).', path.relative(process.cwd(), JSON.stringify(environments)) )) config._msgs.push(util.format( 'Using custom environments found in root of entrypoint (%s).', path.relative(process.cwd(), envfile) )) } catch (e) { config._msgs.push(util.format( 'No custom environments found in root of entrypoint (%s).', path.relative(process.cwd(), envfile) )) } }
/ /.env.js module.exports = { DEBUG: JSON.stringify(true), API: JSON.stringify('https://test.api.com') };
console.log(DEBUG, API) // true, 'https://test.api.com'
Thank you @erikhuisman, that's a really nice addition, I've added this in version 0.5.0.
0.5.0
I did something like this to load some environment variables. Might come in handy to people building for test, staging, production.