rsvp-reader/webpack.config.js

95 lines
2.8 KiB
JavaScript
Raw Normal View History

2019-12-14 10:43:07 +01:00
const path = require('path')
2019-12-10 07:52:36 +01:00
const HtmlWebpackPlugin = require('html-webpack-plugin')
2019-12-13 17:32:18 +01:00
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin')
2019-12-14 10:43:07 +01:00
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
.BundleAnalyzerPlugin
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const WebpackBar = require('webpackbar')
module.exports = (env, argv) => {
const isEnvProduction = argv.mode === 'production'
const isEnvDevelopment = argv.mode === 'development'
2019-12-10 07:52:36 +01:00
2019-12-14 10:43:07 +01:00
return {
output: {
path: path.resolve(__dirname, 'build'),
filename: 'static/js/[name].[contenthash:8].js',
chunkFilename: 'static/js/[name].[contenthash:8].chunk.js'
},
devtool: isEnvProduction ? 'source-map' : 'cheap-module-source-map',
module: {
rules: [
// process javascript with babel
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
// process css. css modules are enabled.
{
test: /\.css$/,
use: [
isEnvDevelopment && 'style-loader',
isEnvProduction && MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: {
localIdentName: isEnvProduction
? '[hash:base64]'
: '[path][name]__[local]'
}
}
2019-12-14 15:23:58 +01:00
},
'postcss-loader'
2019-12-14 10:43:07 +01:00
].filter(Boolean)
}
]
},
optimization: {
2019-12-14 12:03:40 +01:00
minimize: isEnvProduction,
2019-12-14 10:43:07 +01:00
splitChunks: {
chunks: 'all',
name: false
2019-12-14 11:36:59 +01:00
},
runtimeChunk: {
name: entrypoint => `runtime-${entrypoint.name}`
2019-12-10 07:52:36 +01:00
}
2019-12-14 10:43:07 +01:00
},
2020-02-01 12:18:39 +01:00
resolve: { modules: ['src', 'lib', 'node_modules'] },
2019-12-14 10:43:07 +01:00
plugins: [
// creat an index.html
new HtmlWebpackPlugin(),
// show a progress bar
new WebpackBar(),
// create a report.html for bundle size
// extract css to css files
isEnvProduction &&
new MiniCssExtractPlugin({
filename: 'static/css/[name].[contenthash:8].css',
chunkFilename: 'static/css/[name].[contenthash:8].chunk.css'
}),
// use cssnano to minify css
isEnvProduction &&
new OptimizeCssAssetsPlugin({
cssProcessorOptions: {
map: { inline: false, annotation: true }
}
2019-12-14 13:50:17 +01:00
}),
isEnvProduction &&
2019-12-14 13:50:17 +01:00
new BundleAnalyzerPlugin({
analyzerMode: 'static',
openAnalyzer: false
2019-12-14 10:43:07 +01:00
})
// hot reload not working right now
// isEnvDevelopment &&
// new ReactRefreshWebpackPlugin({ disableRefreshCheck: true })
].filter(Boolean),
devServer: {
stats: 'minimal'
}
2019-12-10 07:52:36 +01:00
}
}