Fitbit / webpack-config

Helps to load, extend and merge webpack configs
https://fitbit.github.io/webpack-config
Apache License 2.0
252 stars 18 forks source link

more info on environment support #80

Closed jchip closed 7 years ago

jchip commented 7 years ago

I am trying to find out more info about these two features:

I see that in the readme there's

// Also you may use `'conf/webpack.[NODE_ENV].config.js'`

Is there more info somewhere else?

mdreizin commented 7 years ago

@jchip Fot instance, if you have the following npm script:

"scripts": {
    "start": "NODE_ENV=development webpack-dev-server --config webpack.config.js --progress --port 3000 --https --hot --inline --compress",
    "build": "NODE_ENV=production webpack --config webpack.config.js --hide-modules"
  },

and the following webpack config:

webpack.config.js

const WebpackConfig = require('webpack-config');

module.exports = new WebpackConfig().extend('./webpack.[NODE_ENV].config.js');

If you run npm run start then webpack.development.config.js will be included into webpack.config.js.

If you run npm run build then webpack.production.config.js will be included into webpack.config.js.

Also you may use environment map of webpack-config to do the same:

const WebpackConfig = require('webpack-config');
const environment = require('webpack-config'). environment;

environment.setAll({
  'env': process.env. NODE_ENV
});

module.exports = new WebpackConfig().extend('./webpack.[env].config.js');

In both cases [NODE_ENV] and [env] will be automatically interpolated.

Also if you have any strings which contain [NODE_ENV] or [env] then they also should be interpolated:

const WebpackConfig = require('webpack-config');
const environment = require('webpack-config'). environment;

environment.setAll({
  env: 'bar'
});

const webpackConfig = new WebpackConfig();

webpackConfig.merge({
  foo: 'env'
});

console.log(webpackConfig.toObject()); // => { foo: 'bar' }

Variable aka environment interpolations is designed for extend method, but you may use it for defaults and merge.

For more info please see:

https://github.com/Fitbit/webpack-config/blob/master/test/ConfigStringResolver.spec.js https://github.com/Fitbit/webpack-config/blob/master/test/ConfigEnvironment.spec.js

jchip commented 7 years ago

Thank you for such a thorough answer!

mdreizin commented 7 years ago

@jchip May I close this issue?

mdreizin commented 7 years ago

@jchip Do you have any additional questions?