title: Webpack require expression external
body: <p>I have an expression require which should get resolved in runtime but I can’t get my head around the webpack config for this simple example:</p>
  
  <pre><code>import something from 'module';
  import pkg from './package.json';
  let a;
  
  if (pkg.main) {
     a = require(pkg.main);
  }
  </code></pre>
  
  <p>The resulting build should contain the <code>module</code> but also require <code>./package.json</code> and <code>pkg.main</code> in runtime as commonjs modules — in other words, exclude them from the build.</p>
  
  <p>My <code>webpack.config.js</code> so far:</p>
  
  <pre><code>var webpack = require('webpack');
  
  module.exports = {
    entry: './src/main.js',
    output: {
      filename: '[name].js',
      path: './build'
    },
    target: 'node-webkit',
    plugins: [
      new webpack.ExternalsPlugin('commonjs', './package.json')
    ],
    module: {
      noParse: /\.min\.js/,
      exprContextRegExp: /$^/,
      exprContextCritical: false,
      loaders: [
        {
          test: /\.js$/,
          loader: 'babel',
          exclude: /node_modules/
        }
      ]
    }
  };
  </code></pre>
  
  <p>What happens now is the require for <code>pkg.main</code> results in <code>webpackMissingModule</code> exception and if I remove <code>exprContextRegExp</code>, the require will use context.</p>
  
  <p>Thanks for any help</p>