Skip to content

Instantly share code, notes, and snippets.

@BiosBoy
Created January 12, 2019 23:20
Show Gist options
  • Save BiosBoy/0b3258e647a28984d88ebddc270f85c4 to your computer and use it in GitHub Desktop.
Save BiosBoy/0b3258e647a28984d88ebddc270f85c4 to your computer and use it in GitHub Desktop.
const createConfig = () => {
debug('Creating configuration.');
debug(`Enabling devtools for '${__NODE_ENV__} Mode!'`);
const webpackConfig = {
mode: __DEV__ ? 'development' : 'production',
name: 'client',
target: 'web',
devtool: stageConfig[__NODE_ENV__].devtool,
stats: stageConfig[__NODE_ENV__].stats,
module: {
rules: [...rules]
},
...optimization,
resolve: {
modules: ['node_modules'],
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json']
}
};
// ------------------------------------
// Entry Points
// ------------------------------------
webpackConfig.entry = {
app: ['babel-polyfill', path.resolve(__dirname, 'src/index.js')].concat(
'webpack-hot-middleware/client?path=/__webpack_hmr'
)
};
// ------------------------------------
// Bundle externals
// ------------------------------------
webpackConfig.externals = {
react: 'React',
'react-dom': 'ReactDOM'
};
// ------------------------------------
// Bundle Output
// ------------------------------------
webpackConfig.output = {
filename: '[name].[hash].js',
chunkFilename: '[name].[hash].js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/'
};
// ------------------------------------
// Plugins
// ------------------------------------
debug(`Enable plugins for '${__NODE_ENV__} Mode!'`);
webpackConfig.plugins = [
new webpack.DefinePlugin({
__DEV__,
__PROD__,
__TEST__
}),
...stagePlugins[__NODE_ENV__]
];
// ------------------------------------
// Finishing the Webpack configuration!
// ------------------------------------
debug(`Webpack Bundles is Ready for '${__NODE_ENV__} Mode!'`);
return webpackConfig;
};
module.exports = createConfig();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment