-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.ts
110 lines (103 loc) · 3 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
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
102
103
104
105
106
107
108
109
110
// @ts-nocheck
import { Configuration } from 'webpack';
import path from 'path';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import HtmlWebpackPartialsPlugin from 'html-webpack-partials-plugin'
import DotenvWebpackPlugin from 'dotenv-webpack';
import CircularDependencyPlugin from 'circular-dependency-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import UglifyJsWebpackPlugin from 'uglifyjs-webpack-plugin';
const PATH_LIST = {
SRC: path.resolve(__dirname, 'src'),
APP: path.resolve(__dirname, 'src', 'app'),
INDEX: path.resolve(__dirname, 'src', 'app', 'index.tsx'),
BUILD: path.resolve(__dirname, 'build'),
TEMPLATE: path.resolve(__dirname, 'src', 'index.html'),
SPLASH: path.resolve(__dirname, 'src', 'splash.html')
};
const isProd = process.env.NODE_ENV === 'production';
const styleLoader = isProd ? MiniCssExtractPlugin.loader : 'style-loader';
const stylePlugins = isProd ? [new MiniCssExtractPlugin({ filename: 'style.css' })] : [];
const optimization = isProd
? {
minimize: true,
minimizer: [
new UglifyJsWebpackPlugin({
uglifyOptions: {
output: {
comments: false
}
}
})
],
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all'
}
}
}
}
: undefined;
// @ts-ignore
const webpackConfig: Configuration = {
devtool: isProd ? false : 'source-map',
context: PATH_LIST.SRC,
entry: PATH_LIST.INDEX,
output: {
path: PATH_LIST.BUILD,
filename: '[name][contenthash].min.js',
publicPath: '/',
clean: true
},
resolve: {
extensions: ['.js', '.ts', '.tsx'],
alias: {
app: PATH_LIST.APP,
src: PATH_LIST.SRC
}
},
module: {
rules: [
{
test: /\.svg$/i,
issuer: /\.[jt]sx?$/,
use: ['@svgr/webpack']
},
{
test: /\.(ts|tsx)$/,
use: 'ts-loader',
exclude: /node_modules/
},
{
test: /.less$/,
use: [
styleLoader,
'css-loader',
'postcss-loader',
'less-loader'
]
}
]
},
optimization,
plugins: [
...stylePlugins,
new HtmlWebpackPlugin({
template: PATH_LIST.TEMPLATE
}),
new DotenvWebpackPlugin(),
new CircularDependencyPlugin({
exclude: /a\.js|node_modules/,
failOnError: true,
allowAsyncCycles: false,
cwd: process.cwd()
}),
new HtmlWebpackPartialsPlugin({
path: PATH_LIST.SPLASH
})
]
}
export default webpackConfig;