generated from shoota/react-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.ts
124 lines (119 loc) · 3.18 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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'
import CopyWebpackPlugin from 'copy-webpack-plugin'
import siteConfig from './src/data/site.json'
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.ejs',
templateParameters: { title: siteConfig.blogTitle },
minify: {
collapseWhitespace: true,
removeComments: true,
removeRedundantAttributes: true,
},
}),
new CleanWebpackPlugin(),
new CopyWebpackPlugin([{ from: './assets', to: './assets' }]),
]
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',
},
{
test: /\.(woff|woff2|eot|ttf|svg)$/,
loader: 'file-loader',
},
],
},
optimization: {
splitChunks: {
cacheGroups: {
vendors: {
priority: -10,
test: /[\\/]node_modules[\\/]/,
},
},
chunks: 'async',
minChunks: 1,
minSize: 30000,
name: true,
},
},
// eslint-disable-next-line
// @ts-ignore
devServer,
resolve: {
alias: {
'react-dom': '@hot-loader/react-dom',
},
extensions: ['.tsx', '.ts', '.js', '.jsx'],
modules: ['./node_modules', path.resolve(__dirname, '.', 'src')],
},
}
}
// eslint-disable-next-line import/no-default-export
export default config