-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.js
142 lines (136 loc) · 3.65 KB
/
config.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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
const { WebpackManifestPlugin } = require('webpack-manifest-plugin')
const webpack = require('webpack')
const { merge } = require('webpack-merge')
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
const getServerConfig = require('./config.server')
const getClientConfig = require('./config.client')
function getStats(verbose) {
const stats = verbose
? {
entrypoints: true,
chunks: true,
chunkModules: false,
chunkOrigins: true,
colors: true,
depth: true,
usedExports: true,
providedExports: true,
optimizationBailout: true,
errorDetails: true,
publicPath: true,
performance: true,
reasons: true,
exclude: () => false,
warnings: true,
logging: 'info',
}
: {
logging: 'none',
assets: false,
builtAt: false,
cached: false,
cachedAssets: false,
children: false,
chunks: false,
chunkGroups: false,
chunkModules: false,
chunkOrigins: false,
colors: true,
depth: false,
entrypoints: false,
env: false,
errors: true,
errorDetails: true,
hash: false,
modules: false,
moduleTrace: false,
performance: false,
providedExports: false,
publicPath: false,
reasons: false,
source: false,
timings: false,
usedExports: false,
version: false,
warnings: false,
}
return stats
}
function getCommonConfig({ verbose, debug, staging }) {
return {
mode: debug ? 'development' : 'production',
devtool: debug ? 'inline-source-map' : 'source-map',
module: {
rules: [
{
test: /\.mdx?$/,
use: [
{
loader: '@mdx-js/loader',
/** @type {import('@mdx-js/loader').Options} */
options: {
providerImportSource: '@mdx-js/react',
},
},
],
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
loader: 'ts-loader',
options: {
// disable type checking
// it will be performed in separate process
// thanks to 'fork-ts-checker-webpack-plugin'
transpileOnly: true,
},
},
{
test: /\.(jpg|jpeg|png|gif|pdf)$/i,
type: 'asset/resource',
},
{
test: /\.(woff|woff2|svg|ttf|eot|otf)$/i,
type: 'asset/inline',
},
],
},
stats: getStats(verbose),
resolve: {
extensions: ['.mjs', '.js', '.jsx', '.ts', '.tsx', '.md', '.mdx'],
},
plugins: [
// Common all
new WebpackManifestPlugin({
writeToFileEmit: true,
}),
// DON'T use JSON stringify and yes it needs multiple quotes
// (JSON is imported by babel in a file that use module.exports => X[)
new webpack.DefinePlugin({
'process.env.NODE_ENV': `"${process.env.NODE_ENV || 'development'}"`,
'process.env.STAGING': `${!!staging}`,
}),
new ForkTsCheckerWebpackPlugin(),
],
}
}
function getBaseConfigClient(config, renderHtml) {
const commonCfg = getCommonConfig(config)
const clientCfg = getClientConfig(
config,
renderHtml,
getStats(config.verbose)
)
const conf = merge(commonCfg, clientCfg)
return conf
}
function getBaseConfigServer(config) {
const commonCfg = getCommonConfig(config)
const serverCfg = getServerConfig(config)
const conf = merge(commonCfg, serverCfg)
return conf
}
module.exports = {
getBaseConfigClient,
getBaseConfigServer,
}