forked from patternfly-labs/react-form-wizard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
74 lines (71 loc) · 2.93 KB
/
webpack.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* eslint-disable i18next/no-literal-string */
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin'
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import webpack from 'webpack'
import { Configuration as DevServerConfiguration } from 'webpack-dev-server'
module.exports = function (_env: unknown, argv: { hot: boolean; mode: string | undefined }) {
const isProduction = argv.mode === 'production' || argv.mode === undefined
const isDevelopment = !isProduction
const config: webpack.Configuration & { devServer: DevServerConfiguration } = {
entry: './wizards',
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
},
module: {
rules: [
{ test: /\.(hbs|yaml)$/, type: 'asset/source' },
{ test: /\.(svg)$/, use: '@svgr/webpack' },
{ test: /\.(jpg|jpeg|png|gif|ttf|eot|woff|woff2)$/, type: 'asset/resource' },
{
test: /\.css$/,
use: isDevelopment ? ['style-loader', 'css-loader'] : [MiniCssExtractPlugin.loader, 'css-loader'],
},
{
test: /\.(ts|tsx|js|jsx)$/,
exclude: /node_modules/,
loader: require.resolve('babel-loader'),
options: {
plugins: [isDevelopment && require.resolve('react-refresh/babel')].filter(Boolean),
},
type: 'javascript/auto',
},
],
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': isProduction ? JSON.stringify('production') : JSON.stringify('development'),
}),
isDevelopment && new ReactRefreshWebpackPlugin(),
new HtmlWebpackPlugin({ title: 'Form Wizard', favicon: 'wizards/assets/favicon.svg' }),
new MiniCssExtractPlugin({
filename: '[name].[contenthash:8].css',
chunkFilename: '[id].[contenthash:8].css',
ignoreOrder: false, // Enable to remove warnings about conflicting order
}),
].filter(Boolean) as webpack.WebpackPluginInstance[],
output: {
publicPath: isProduction ? '/react-form-wizard/' : '/',
},
optimization: {
minimizer: [
`...`,
new CssMinimizerPlugin({
minimizerOptions: {
preset: ['default', { mergeLonghand: false }],
},
}),
],
},
devServer: {
port: 3000,
open: false,
historyApiFallback: true,
compress: true,
hot: true,
},
devtool: isDevelopment && 'source-map',
}
return config
}