-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
105 lines (98 loc) · 2.7 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
import os from 'os'
import { Configuration } from 'webpack'
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin'
import HtmlWebpackPlugin from 'html-webpack-plugin'
// TODO https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/556
// import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'
// eslint-disable-next-line @typescript-eslint/no-var-requires
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
// eslint-disable-next-line @typescript-eslint/no-var-requires
const TerserPlugin = require('terser-webpack-plugin')
const cpus = os.cpus().length
const tsLoaderWorkers = cpus > 3 ? cpus - 2 : 1
type DevServer = {
[key: string]: any // eslint-disable-line @typescript-eslint/no-explicit-any
}
const config: Configuration & DevServer = {
devtool: 'source-map',
entry: {
app: `${__dirname}/src/App.tsx`,
},
output: {
filename: '[name].js',
path: `${__dirname}/dist`,
publicPath: '/',
},
devServer: {
historyApiFallback: {
rewrites: [{ from: /^\/*/, to: '/index.html' }],
},
host: '0.0.0.0',
port: 3000,
hot: true,
liveReload: true,
},
module: {
rules: [
{
test: /\.tsx?$/,
use: [
{
loader: 'cache-loader',
},
{
loader: 'ts-loader',
options: {
happyPackMode: true, // IMPORTANT! use happyPackMode mode to speed-up compilation and reduce errors reported to webpack
// transpileOnly: true, TODO
},
},
{
// run compilation threaded
loader: 'thread-loader',
options: {
// there should be 1 cpu for the fork-ts-checker-webpack-plugin
workers: tsLoaderWorkers,
},
},
],
},
{
test: /\.less$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'less-loader',
// import the antd theme, webpack build show .bezierEasingMixin error ?
// https://github.com/ant-design/ant-design/issues/7927
options: {
lessOptions: {
javascriptEnabled: true,
},
},
},
],
},
],
},
performance: { hints: false },
optimization: {
minimizer: [new TerserPlugin(), new CssMinimizerPlugin()],
},
plugins: [
// TODO
// new ForkTsCheckerWebpackPlugin({
// async: true,
// }),
new MiniCssExtractPlugin(),
new HtmlWebpackPlugin({
template: './src/index.html',
filename: './index.html',
}),
],
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
},
}
export default config