This repository has been archived by the owner on Feb 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
98 lines (87 loc) · 2.58 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
'use strict';
// https://webpack.js.org/guides/
require('dotenv').config();
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const SpriteLoaderPlugin = require('svg-sprite-loader/plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const rootPath = path.resolve(__dirname);
const PRODUCTION = process.env.NODE_ENV === 'production';
module.exports = {
entry: './src/index.tsx',
// https://webpack.js.org/configuration/devtool/
devtool: PRODUCTION ? 'source-map' : 'eval-cheap-module-source-map',
mode: PRODUCTION ? 'production' : 'development',
output: {
filename: 'main.[contenthash].js',
chunkFilename: '[id].[contenthash].js',
path: path.resolve(rootPath, 'dist'),
publicPath: '/',
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(rootPath, PRODUCTION ? 'public/index.html' : 'public/index.dev.html'),
inject: true,
favicon: PRODUCTION
? path.resolve(rootPath, 'src/assets/logo.svg')
: path.resolve(rootPath, 'src/assets/logo-dev.svg'),
}),
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: '[name].[contenthash].css',
chunkFilename: '[id].[contenthash].css',
}),
new SpriteLoaderPlugin(),
// new require('webpack-bundle-analyzer').BundleAnalyzerPlugin,
],
devServer: {
static: {
directory: path.resolve(__dirname, 'public'),
},
hot: true,
compress: true,
historyApiFallback: true,
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json', '.wasm'],
},
module: {
rules: [
{
test: /\.tsx?$/,
use: [{ loader: 'babel-loader' }],
},
{
test: /\.css$/,
use: [PRODUCTION ? MiniCssExtractPlugin.loader : { loader: 'style-loader' }, { loader: 'css-loader' }],
},
{ test: /\.(png|jpe?g|gif|woff2)$/, use: ['file-loader'] },
{
test: /\.svg$/,
loader: 'svg-sprite-loader',
options: {
extract: true,
spriteFilename: '[contenthash].svg',
esModule: false,
},
},
],
},
// externals: PRODUCTION
// ? {
// react: 'React',
// 'react-dom': 'ReactDOM',
// }
// : {},
optimization: {
minimize: PRODUCTION,
splitChunks: {
chunks: 'all',
minSize: 1000000,
},
minimizer: [new TerserPlugin(), new CssMinimizerPlugin()],
},
};