-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.ts
105 lines (101 loc) · 2.62 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 path from 'path'
import webpack, { ConfigurationFactory, Configuration } from 'webpack'
import { Configuration as DevServerConfiguration } from 'webpack-dev-server'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import { CleanWebpackPlugin } from 'clean-webpack-plugin'
const config: ConfigurationFactory = (_env, { mode }) => {
const plugins: Configuration['plugins'] = [
new webpack.HotModuleReplacementPlugin(),
new webpack.ProgressPlugin(),
new MiniCssExtractPlugin({
filename: '[name]-[hash].css',
chunkFilename: '[id].css',
ignoreOrder: false,
}),
new HtmlWebpackPlugin({ template: './src/index.html' }),
new CleanWebpackPlugin(),
]
const devServer: DevServerConfiguration = {
publicPath: '/',
contentBase: path.resolve(__filename, '../', 'public'),
host: '0.0.0.0',
port: 3035,
disableHostCheck: true,
headers: {
'Access-Control-Allow-Origin': '*',
},
historyApiFallback: {
rewrites: [{ from: /^\/*/, to: '/index.html' }],
},
open: false,
inline: true,
hot: true,
}
return {
entry: {
app: './src/index.tsx',
},
output: {
publicPath: './',
path: path.resolve(__filename, '../', 'public'),
filename: '[name]-[hash].js',
},
plugins,
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'babel-loader',
include: [path.resolve(__dirname)],
exclude: [/node_modules/],
options: {
cacheDirectory: true,
envName: mode || 'development',
},
},
{
test: /\.less$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
},
'css-loader',
{
loader: 'less-loader',
// https://github.com/ant-design/ant-design/issues/7927
options: { javascriptEnabled: true },
},
],
},
{
test: /\.html$/,
loader: 'html-loader',
},
],
},
optimization: {
splitChunks: {
cacheGroups: {
vendors: {
priority: -10,
test: /[\\/]node_modules[\\/]/,
},
},
chunks: 'async',
minChunks: 1,
minSize: 30000,
name: true,
},
},
devServer,
resolve: {
alias: {
'react-dom': '@hot-loader/react-dom',
},
extensions: ['.tsx', '.ts', '.js', '.jsx'],
modules: ['./node_modules', path.resolve(__dirname, '.', 'src')],
},
}
}
export default config