Repository URL to install this package:
|
Version:
0.0.2 ▾
|
@doodle/frontend-config
/
webpack.react.v1.js
|
|---|
const path = require('path');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const plugins = [
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development'),
},
}),
];
/**
* Default webpack configuration for first generation of React frontends.
* @todo WORK IN PROGRESS – This file cannot be used alone because it still relies on the gulp pipeline.
*
* @param {string} publicPath The path where the frontend will be exposed
* @param {prod} boolean Whether we are building the production bundle
* @param {analyze} boolean Whether to run the bundle analyzer
*/
module.exports = ({ publicPath, prod, analyze }) => ({
entry: ['./src/client', prod ? null : 'webpack-hot-middleware/client?reload=true'].filter(entry => entry),
devtool: process.env.NODE_ENV === 'development' ? 'source-map' : false,
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].bundle.js',
chunkFilename: '[name].bundle.js',
publicPath: `/${publicPath}/assets/`,
},
mode: prod ? 'production' : 'development',
resolve: {
alias: {
'react-redux': path.resolve('./node_modules/react-redux'),
'redux-saga': path.resolve('./node_modules/redux-saga'),
'react-dom': path.resolve('./node_modules/react-dom'),
react: path.resolve('./node_modules/react'),
},
modules: ['node_modules'],
},
optimization: {
minimize: prod,
},
plugins: [
prod ? null : new webpack.HotModuleReplacementPlugin(),
...plugins,
analyze
? new BundleAnalyzerPlugin({
generateStatsFile: true,
})
: null,
new CopyWebpackPlugin([
{
from: `dist/bundle.css`,
to: `bundle.css`,
},
{
from: `node_modules/@doodle/components/assets`,
to: `assets`,
},
{
from: `node_modules/@doodle/components/views/assets`,
},
{
from: `dist`,
},
]),
],
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
include: path.resolve(__dirname, 'src'),
},
{
test: /\.svg/,
loader: 'svg-react-loader',
},
],
},
});