-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
101 lines (99 loc) · 2.62 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
100
101
const path = require('path');
const { CheckerPlugin } = require('awesome-typescript-loader');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserJSPlugin = require('terser-webpack-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const { NODE_ENV } = process.env;
const isDev = NODE_ENV === 'development';
if (NODE_ENV !== 'development' && NODE_ENV !== 'production')
throw new Error("'NODE_ENV' must be either 'development' or 'production'");
/** @type {import('webpack').Configuration} */
module.exports = {
entry: './src/index.ts',
mode: isDev ? 'development' : 'production',
devServer: !isDev
? undefined
: {
contentBase: path.join(__dirname, 'public'),
port: 3000,
open: true,
hot: true,
inline: true,
compress: true,
watchContentBase: true,
},
optimization: isDev
? undefined
: {
minimize: true,
minimizer: [new TerserJSPlugin({}), new OptimizeCSSAssetsPlugin({})],
},
devtool: isDev ? 'source-map' : undefined,
module: {
rules: [
{
test: /\.ts?$/,
use: 'awesome-typescript-loader',
exclude: '/node_modules/',
},
{
test: /\.s(c|a)ss$/,
use: [
isDev ? 'style-loader' : MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: { importLoaders: 1 },
},
{
loader: 'sass-loader',
options: { sourceMap: isDev },
},
],
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [
{
loader: 'file-loader',
options: {
outputPath: './static/assets/',
},
},
],
},
],
},
resolve: { extensions: ['.tsx', '.ts', '.js', '.jsx'] },
output: {
filename: './static/js/main.[hash].js',
path: path.join(__dirname, 'build'),
},
plugins: [
new CheckerPlugin(),
new ESLintPlugin(),
new HtmlWebpackPlugin({
template: path.join(__dirname, 'public', 'index.html'),
}),
new MiniCssExtractPlugin({
filename: './static/css/main.[hash].css',
chunkFilename: '[id].css',
}),
new CopyPlugin({
patterns: [
{
from: './public/*',
to: '.',
flatten: true,
},
{
flatten: true,
from: './public/icons/*',
to: 'icons',
},
],
}),
],
};