petehunt / webpack-howto

10.12k stars 697 forks source link

Feature flags for different entry points #73

Open iwano opened 8 years ago

iwano commented 8 years ago

Is there a way to set a feature flag with the current entry point name so we could reuse components but at the same time change them slightly (deeply nested imports for example). Something like:

module.exports = {
  entry: {
    main: './src/main.js',
    admin: './src/admin.js'
  },
  output: {
    filename: "[name].bundle.js"       
  },
};

var definePlugin = new webpack.DefinePlugin({
  __APP_MODE__: "[name]"
});

In order to do something like:

import Menu from './components/menu'

/components/menu.js

if (__APP_MODE__) {
  module.exports = require('./admin/menu');
} else {
  module.exports = require('./main/menu');
}