title: Exclude module from webpack minification
body: <p>We are using WebPack in a single page application. The application is deployed to many environments. We have a requirement where the application needs to call a specific endpoint in a given environment.</p>
  
  <p>In order to provide the endpoint address for the given environment is to have an environments module. This is the current solution (there are many and this is not the point of the question). However we need to exclude the config.js from minification so that it can be overwritten as part of the deployment process.</p>
  
  <p>The config.js looks like the following:</p>
  
  <pre><code>module.exports = {
      env: {
          endpointUrl: 'http://1.2.3.4',
          authUrl: 'http://5.6.7.8'
      }
  };
  </code></pre>
  
  <p>And is referenced using the following:</p>
  
  <pre><code>const endpointUrl = config.env.endpointUrl;
  const authUrl = config.env.authUrl;
  </code></pre>
  
  <p>The WebPack config looks like the following:</p>
  
  <pre><code>var webpack = require('webpack');
  ​
  module.exports = {
      entry: {
          main: './src/js/main.jsx',
          login: './src/js/login-main.jsx'
      },
      output: {
          path: __dirname + '/dist',
          filename: '[name].bundle.js'
      },
      devtool: 'source-map',
      module: {
          loaders: [{
              test: /.jsx?$/,
              exclude: /node_modules/,
              loader: 'babel-loader',
              plugins: ['transform-react-jsx'],
              query: {stage: 0}
          }, {
              test: /\.jsx?$/,
              exclude: /node_modules/,
              loader: 'eslint-loader'
          }]
      },
      plugins: [
          new webpack.ProvidePlugin({
              fetch: 'imports?this=&gt;global!exports?global.fetch!whatwg-fetch'
          }),
          new webpack.DefinePlugin({
              __DEV__: JSON.stringify(JSON.parse(process.env.DEV || false))
          })
      ]
  };
  </code></pre>
  
  <p>So far we have looked at <a href="http://webpack.github.io/docs/library-and-externals.html" rel="noreferrer">externals</a> and <a href="https://webpack.github.io/docs/loaders.html" rel="noreferrer">module loaders</a> but have not found anything that works. The exclude in the module loader still causes the module to be minified.</p>
  
  <p>Some SO questions that we have looked at:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/33154285/exclude-react-from-webpack-bundle">Exclude react from webpack bundle</a></li>
  <li><a href="https://stackoverflow.com/questions/22530254/webpack-and-external-libraries">Webpack and external libraries</a></li>
  <li><a href="https://stackoverflow.com/questions/25834396/how-can-i-exclude-code-path-when-bundling-with-webpack-browserify">How can I exclude code path when bundling with webpack/browserify?</a></li>
  </ul>