forked from wojtekmaj/react-lifecycle-methods-diagram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
99 lines (96 loc) · 2.42 KB
/
webpack.config.js
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const webpack = require('webpack');
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const isProduction = process.env.NODE_ENV === 'production';
const isDevelopment = !isProduction;
module.exports = {
mode: isProduction ? 'production' : 'development',
bail: isProduction,
context: path.join(__dirname, 'src'),
entry: {
src: './index.jsx',
},
output: {
path: path.resolve(__dirname, 'dist'),
publicPath: '',
filename: '[name].[chunkhash:8].js',
chunkFilename: '[name].[chunkhash:8].js',
},
resolve: {
extensions: ['.js', '.jsx'],
},
module: {
rules: [
{
test: /\.jsx?$/,
include: path.resolve(__dirname, 'src'),
use: [
{
loader: 'babel-loader',
options: {
plugins: [isDevelopment && 'react-refresh/babel'].filter(Boolean),
},
},
],
},
{
test: /\.css$/,
use: [
isProduction ? MiniCssExtractPlugin.loader : 'style-loader',
'css-loader',
],
},
{
test: /\.less$/,
use: [
isProduction ? MiniCssExtractPlugin.loader : 'style-loader',
'css-loader',
'less-loader',
],
},
].filter(Boolean),
},
plugins: [
new webpack.EnvironmentPlugin({
NODE_ENV: 'production', // use 'production' unless process.env.NODE_ENV is defined
}),
new CopyWebpackPlugin({
patterns: [
'.htaccess',
'static/favicon.ico',
'static/ogimage.png',
],
}),
new HtmlWebpackPlugin({
template: 'index.html',
}),
isProduction && new MiniCssExtractPlugin({
filename: '[name].[chunkhash:8].css',
chunkFilename: '[name].[chunkhash:8].css',
}),
isDevelopment && new ReactRefreshWebpackPlugin(),
].filter(Boolean),
optimization: {
moduleIds: 'named',
splitChunks: {
chunks: 'all',
maxInitialRequests: 30,
maxAsyncRequests: 30,
maxSize: 100000,
},
},
stats: {
assetsSort: '!size',
entrypoints: false,
},
devServer: {
historyApiFallback: true,
port: 3000,
static: {
directory: path.join(__dirname, 'dist'),
},
},
};