forked from dragonman225/jade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.utils.js
90 lines (85 loc) · 2.35 KB
/
webpack.config.utils.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
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
function getCommonPlugins() {
return [new MiniCssExtractPlugin()]
}
/**
* @see https://webpack.js.org/configuration/module/
* @param {'development' | 'production'} mode
*/
function getModuleConfig(mode) {
return {
rules: [
{
test: /\.tsx?$/,
use: [
{
loader: 'babel-loader',
options: {
presets: [
'@babel/preset-env',
'@babel/preset-typescript',
'@babel/preset-react',
],
plugins: [
'@babel/proposal-class-properties',
'@babel/proposal-object-rest-spread',
/**
* For async/await
* create-react-app's usage:
* https://github.com/facebook/create-react-app/blob/a422bf227cf5294a34d68696664e9568a152fd8f/packages/babel-preset-react-app/create.js#L178
* babel documentation
* https://babeljs.io/docs/en/babel-plugin-transform-runtime
*/
'@babel/plugin-transform-runtime',
/** For HMR */
mode === 'development' && 'react-refresh/babel',
].filter(Boolean),
},
},
],
},
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
/**
* Move assets to `assets/`. New API that replaces file-loader.
* @see https://webpack.js.org/guides/asset-modules/
* @see https://webpack.js.org/loaders/css-loader/#assets
*/
{
test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/i,
type: 'asset/resource',
generator: {
filename: 'assets/[hash][ext][query]',
},
},
],
}
}
/** @see https://webpack.js.org/configuration/resolve/ */
function getResolveConfig() {
return {
extensions: ['.tsx', '.ts', '.js', '.css'],
}
}
/** @see https://webpack.js.org/configuration/optimization/ */
function getOptimizationConfig() {
return {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
},
},
},
}
}
module.exports = {
getCommonPlugins,
getModuleConfig,
getResolveConfig,
getOptimizationConfig,
}