Webpack -- include configuration file as external resource
<p>As the applicaiton grows, it is time to remove the hard coded things from the code. Time to implement proper configuration file.</p>

<p>I am thinking to use webpack, and to include configuration file, so I can require it in react.js application.</p>

<p>This is what I have done (webpack.config):</p>

<pre><code>var path = require('path');
var webpack = require('webpack');
module.exports = {
entry: [
  './src/app.js'
],
output: {
  path: path.join(__dirname, 'public/js'),
  filename: 'app.built.js'
},
externals: {
  'Configurator':  require('./config/config-dev.json')
},
module: {
  loaders: [
    { test: /\.js$/, exclude: /node_modules/, loader: 'babel?presets[]=es2015&amp;presets[]=react' },
    { test: /\.css$/, loader: "style-loader!css-loader" }
  ]
}
 };
</code></pre>

<p>My JSON file:</p>

<pre><code>{
 "product": {
 "getProducts": "/product",
 "updateProduct": "/updateproduct",
 "deleteProduct": "/deleteproduct"
},
 "project": {
 "getProjects": "/project",
 "updateProduct": "/updateproject",
 "deleteProduct": "/deleteproject"    
}  
}
</code></pre>

<p>And in one of the components in React components I try this:</p>

<pre><code>var MyFile = require('Configurator');
</code></pre>

<p>There is no error, webpack finds the file. In console I see this:</p>

<pre><code>var MyFile = __webpack_require__(412);
</code></pre>

<p>But MyFile is undefined.</p>

<p>What I am doing wrong?</p>