|
@@ -0,0 +1,804 @@
|
|
1
|
+'use strict';
|
|
2
|
+
|
|
3
|
+const fs = require('fs');
|
|
4
|
+const path = require('path');
|
|
5
|
+const webpack = require('webpack');
|
|
6
|
+const resolve = require('resolve');
|
|
7
|
+const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
8
|
+const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
|
|
9
|
+const InlineChunkHtmlPlugin = require('react-dev-utils/InlineChunkHtmlPlugin');
|
|
10
|
+const TerserPlugin = require('terser-webpack-plugin');
|
|
11
|
+const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
12
|
+const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
|
|
13
|
+const { WebpackManifestPlugin } = require('webpack-manifest-plugin');
|
|
14
|
+const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
|
|
15
|
+const WorkboxWebpackPlugin = require('workbox-webpack-plugin');
|
|
16
|
+const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
|
|
17
|
+const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent');
|
|
18
|
+const ESLintPlugin = require('eslint-webpack-plugin');
|
|
19
|
+const paths = require('./paths');
|
|
20
|
+const modules = require('./modules');
|
|
21
|
+const getClientEnvironment = require('./env');
|
|
22
|
+const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
|
|
23
|
+const ForkTsCheckerWebpackPlugin =
|
|
24
|
+ process.env.TSC_COMPILE_ON_ERROR === 'true'
|
|
25
|
+ ? require('react-dev-utils/ForkTsCheckerWarningWebpackPlugin')
|
|
26
|
+ : require('react-dev-utils/ForkTsCheckerWebpackPlugin');
|
|
27
|
+const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
|
|
28
|
+
|
|
29
|
+const createEnvironmentHash = require('./webpack/persistentCache/createEnvironmentHash');
|
|
30
|
+
|
|
31
|
+// Source maps are resource heavy and can cause out of memory issue for large source files.
|
|
32
|
+const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
|
|
33
|
+
|
|
34
|
+const reactRefreshRuntimeEntry = require.resolve('react-refresh/runtime');
|
|
35
|
+const reactRefreshWebpackPluginRuntimeEntry = require.resolve(
|
|
36
|
+ '@pmmmwh/react-refresh-webpack-plugin'
|
|
37
|
+);
|
|
38
|
+const babelRuntimeEntry = require.resolve('babel-preset-react-app');
|
|
39
|
+const babelRuntimeEntryHelpers = require.resolve(
|
|
40
|
+ '@babel/runtime/helpers/esm/assertThisInitialized',
|
|
41
|
+ { paths: [babelRuntimeEntry] }
|
|
42
|
+);
|
|
43
|
+const babelRuntimeRegenerator = require.resolve('@babel/runtime/regenerator', {
|
|
44
|
+ paths: [babelRuntimeEntry],
|
|
45
|
+});
|
|
46
|
+
|
|
47
|
+// Some apps do not need the benefits of saving a web request, so not inlining the chunk
|
|
48
|
+// makes for a smoother build process.
|
|
49
|
+const shouldInlineRuntimeChunk = process.env.INLINE_RUNTIME_CHUNK !== 'false';
|
|
50
|
+
|
|
51
|
+const emitErrorsAsWarnings = process.env.ESLINT_NO_DEV_ERRORS === 'true';
|
|
52
|
+const disableESLintPlugin = process.env.DISABLE_ESLINT_PLUGIN === 'true';
|
|
53
|
+
|
|
54
|
+const imageInlineSizeLimit = parseInt(
|
|
55
|
+ process.env.IMAGE_INLINE_SIZE_LIMIT || '10000'
|
|
56
|
+);
|
|
57
|
+
|
|
58
|
+// Check if TypeScript is setup
|
|
59
|
+const useTypeScript = fs.existsSync(paths.appTsConfig);
|
|
60
|
+
|
|
61
|
+// Check if Tailwind config exists
|
|
62
|
+const useTailwind = fs.existsSync(
|
|
63
|
+ path.join(paths.appPath, 'tailwind.config.js')
|
|
64
|
+);
|
|
65
|
+
|
|
66
|
+// Get the path to the uncompiled service worker (if it exists).
|
|
67
|
+const swSrc = paths.swSrc;
|
|
68
|
+
|
|
69
|
+// style files regexes
|
|
70
|
+const cssRegex = /\.css$/;
|
|
71
|
+const cssModuleRegex = /\.module\.css$/;
|
|
72
|
+const sassRegex = /\.(scss|sass)$/;
|
|
73
|
+const sassModuleRegex = /\.module\.(scss|sass)$/;
|
|
74
|
+const lessRegex = /\.less$/;
|
|
75
|
+const lessModuleRegex = /\.module\.less$/;
|
|
76
|
+
|
|
77
|
+const hasJsxRuntime = (() => {
|
|
78
|
+ if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') {
|
|
79
|
+ return false;
|
|
80
|
+ }
|
|
81
|
+
|
|
82
|
+ try {
|
|
83
|
+ require.resolve('react/jsx-runtime');
|
|
84
|
+ return true;
|
|
85
|
+ } catch (e) {
|
|
86
|
+ return false;
|
|
87
|
+ }
|
|
88
|
+})();
|
|
89
|
+
|
|
90
|
+// This is the production and development configuration.
|
|
91
|
+// It is focused on developer experience, fast rebuilds, and a minimal bundle.
|
|
92
|
+module.exports = function (webpackEnv) {
|
|
93
|
+ const isEnvDevelopment = webpackEnv === 'development';
|
|
94
|
+ const isEnvProduction = webpackEnv === 'production';
|
|
95
|
+
|
|
96
|
+ // Variable used for enabling profiling in Production
|
|
97
|
+ // passed into alias object. Uses a flag if passed into the build command
|
|
98
|
+ const isEnvProductionProfile =
|
|
99
|
+ isEnvProduction && process.argv.includes('--profile');
|
|
100
|
+
|
|
101
|
+ // We will provide `paths.publicUrlOrPath` to our app
|
|
102
|
+ // as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
|
|
103
|
+ // Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
|
|
104
|
+ // Get environment variables to inject into our app.
|
|
105
|
+ const env = getClientEnvironment(paths.publicUrlOrPath.slice(0, -1));
|
|
106
|
+
|
|
107
|
+ const shouldUseReactRefresh = env.raw.FAST_REFRESH;
|
|
108
|
+
|
|
109
|
+ // common function to get style loaders
|
|
110
|
+ const getStyleLoaders = (cssOptions, preProcessor) => {
|
|
111
|
+ const loaders = [
|
|
112
|
+ isEnvDevelopment && require.resolve('style-loader'),
|
|
113
|
+ isEnvProduction && {
|
|
114
|
+ loader: MiniCssExtractPlugin.loader,
|
|
115
|
+ // css is located in `static/css`, use '../../' to locate index.html folder
|
|
116
|
+ // in production `paths.publicUrlOrPath` can be a relative path
|
|
117
|
+ options: paths.publicUrlOrPath.startsWith('.')
|
|
118
|
+ ? { publicPath: '../../' }
|
|
119
|
+ : {},
|
|
120
|
+ },
|
|
121
|
+ {
|
|
122
|
+ loader: require.resolve('css-loader'),
|
|
123
|
+ options: cssOptions,
|
|
124
|
+ },
|
|
125
|
+ {
|
|
126
|
+ // Options for PostCSS as we reference these options twice
|
|
127
|
+ // Adds vendor prefixing based on your specified browser support in
|
|
128
|
+ // package.json
|
|
129
|
+ loader: require.resolve('postcss-loader'),
|
|
130
|
+ options: {
|
|
131
|
+ postcssOptions: {
|
|
132
|
+ // Necessary for external CSS imports to work
|
|
133
|
+ // https://github.com/facebook/create-react-app/issues/2677
|
|
134
|
+ ident: 'postcss',
|
|
135
|
+ config: false,
|
|
136
|
+ plugins: !useTailwind
|
|
137
|
+ ? [
|
|
138
|
+ 'postcss-flexbugs-fixes',
|
|
139
|
+ [
|
|
140
|
+ 'postcss-preset-env',
|
|
141
|
+ {
|
|
142
|
+ autoprefixer: {
|
|
143
|
+ flexbox: 'no-2009',
|
|
144
|
+ },
|
|
145
|
+ stage: 3,
|
|
146
|
+ },
|
|
147
|
+ ],
|
|
148
|
+ // Adds PostCSS Normalize as the reset css with default options,
|
|
149
|
+ // so that it honors browserslist config in package.json
|
|
150
|
+ // which in turn let's users customize the target behavior as per their needs.
|
|
151
|
+ 'postcss-normalize',
|
|
152
|
+ ]
|
|
153
|
+ : [
|
|
154
|
+ 'tailwindcss',
|
|
155
|
+ 'postcss-flexbugs-fixes',
|
|
156
|
+ [
|
|
157
|
+ 'postcss-preset-env',
|
|
158
|
+ {
|
|
159
|
+ autoprefixer: {
|
|
160
|
+ flexbox: 'no-2009',
|
|
161
|
+ },
|
|
162
|
+ stage: 3,
|
|
163
|
+ },
|
|
164
|
+ ],
|
|
165
|
+ ],
|
|
166
|
+ },
|
|
167
|
+ sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
|
|
168
|
+ },
|
|
169
|
+ },
|
|
170
|
+ ].filter(Boolean);
|
|
171
|
+ if (preProcessor) {
|
|
172
|
+ loaders.push(
|
|
173
|
+ {
|
|
174
|
+ loader: require.resolve('resolve-url-loader'),
|
|
175
|
+ options: {
|
|
176
|
+ sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
|
|
177
|
+ root: paths.appSrc,
|
|
178
|
+ },
|
|
179
|
+ },
|
|
180
|
+ {
|
|
181
|
+ loader: require.resolve(preProcessor),
|
|
182
|
+ options: {
|
|
183
|
+ sourceMap: true,
|
|
184
|
+ },
|
|
185
|
+ }
|
|
186
|
+ );
|
|
187
|
+ }
|
|
188
|
+ return loaders;
|
|
189
|
+ };
|
|
190
|
+
|
|
191
|
+ return {
|
|
192
|
+ target: ['browserslist'],
|
|
193
|
+ // Webpack noise constrained to errors and warnings
|
|
194
|
+ stats: 'errors-warnings',
|
|
195
|
+ mode: isEnvProduction ? 'production' : isEnvDevelopment && 'development',
|
|
196
|
+ // Stop compilation early in production
|
|
197
|
+ bail: isEnvProduction,
|
|
198
|
+ devtool: isEnvProduction
|
|
199
|
+ ? shouldUseSourceMap
|
|
200
|
+ ? 'source-map'
|
|
201
|
+ : false
|
|
202
|
+ : isEnvDevelopment && 'cheap-module-source-map',
|
|
203
|
+ // These are the "entry points" to our application.
|
|
204
|
+ // This means they will be the "root" imports that are included in JS bundle.
|
|
205
|
+ entry: paths.appIndexJs,
|
|
206
|
+ output: {
|
|
207
|
+ // The build folder.
|
|
208
|
+ path: paths.appBuild,
|
|
209
|
+ // Add /* filename */ comments to generated require()s in the output.
|
|
210
|
+ pathinfo: isEnvDevelopment,
|
|
211
|
+ // There will be one main bundle, and one file per asynchronous chunk.
|
|
212
|
+ // In development, it does not produce real files.
|
|
213
|
+ filename: isEnvProduction
|
|
214
|
+ ? 'static/js/[name].[contenthash:8].js'
|
|
215
|
+ : isEnvDevelopment && 'static/js/bundle.js',
|
|
216
|
+ // There are also additional JS chunk files if you use code splitting.
|
|
217
|
+ chunkFilename: isEnvProduction
|
|
218
|
+ ? 'static/js/[name].[contenthash:8].chunk.js'
|
|
219
|
+ : isEnvDevelopment && 'static/js/[name].chunk.js',
|
|
220
|
+ assetModuleFilename: 'static/media/[name].[hash][ext]',
|
|
221
|
+ // webpack uses `publicPath` to determine where the app is being served from.
|
|
222
|
+ // It requires a trailing slash, or the file assets will get an incorrect path.
|
|
223
|
+ // We inferred the "public path" (such as / or /my-project) from homepage.
|
|
224
|
+ publicPath: paths.publicUrlOrPath,
|
|
225
|
+ // Point sourcemap entries to original disk location (format as URL on Windows)
|
|
226
|
+ devtoolModuleFilenameTemplate: isEnvProduction
|
|
227
|
+ ? info =>
|
|
228
|
+ path
|
|
229
|
+ .relative(paths.appSrc, info.absoluteResourcePath)
|
|
230
|
+ .replace(/\\/g, '/')
|
|
231
|
+ : isEnvDevelopment &&
|
|
232
|
+ (info => path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')),
|
|
233
|
+ },
|
|
234
|
+ cache: {
|
|
235
|
+ type: 'filesystem',
|
|
236
|
+ version: createEnvironmentHash(env.raw),
|
|
237
|
+ cacheDirectory: paths.appWebpackCache,
|
|
238
|
+ store: 'pack',
|
|
239
|
+ buildDependencies: {
|
|
240
|
+ defaultWebpack: ['webpack/lib/'],
|
|
241
|
+ config: [__filename],
|
|
242
|
+ tsconfig: [paths.appTsConfig, paths.appJsConfig].filter(f =>
|
|
243
|
+ fs.existsSync(f)
|
|
244
|
+ ),
|
|
245
|
+ },
|
|
246
|
+ },
|
|
247
|
+ infrastructureLogging: {
|
|
248
|
+ level: 'none',
|
|
249
|
+ },
|
|
250
|
+ optimization: {
|
|
251
|
+ minimize: isEnvProduction,
|
|
252
|
+ minimizer: [
|
|
253
|
+ // This is only used in production mode
|
|
254
|
+ new TerserPlugin({
|
|
255
|
+ terserOptions: {
|
|
256
|
+ parse: {
|
|
257
|
+ // We want terser to parse ecma 8 code. However, we don't want it
|
|
258
|
+ // to apply any minification steps that turns valid ecma 5 code
|
|
259
|
+ // into invalid ecma 5 code. This is why the 'compress' and 'output'
|
|
260
|
+ // sections only apply transformations that are ecma 5 safe
|
|
261
|
+ // https://github.com/facebook/create-react-app/pull/4234
|
|
262
|
+ ecma: 8,
|
|
263
|
+ },
|
|
264
|
+ compress: {
|
|
265
|
+ ecma: 5,
|
|
266
|
+ warnings: false,
|
|
267
|
+ // Disabled because of an issue with Uglify breaking seemingly valid code:
|
|
268
|
+ // https://github.com/facebook/create-react-app/issues/2376
|
|
269
|
+ // Pending further investigation:
|
|
270
|
+ // https://github.com/mishoo/UglifyJS2/issues/2011
|
|
271
|
+ comparisons: false,
|
|
272
|
+ // Disabled because of an issue with Terser breaking valid code:
|
|
273
|
+ // https://github.com/facebook/create-react-app/issues/5250
|
|
274
|
+ // Pending further investigation:
|
|
275
|
+ // https://github.com/terser-js/terser/issues/120
|
|
276
|
+ inline: 2,
|
|
277
|
+ },
|
|
278
|
+ mangle: {
|
|
279
|
+ safari10: true,
|
|
280
|
+ },
|
|
281
|
+ // Added for profiling in devtools
|
|
282
|
+ keep_classnames: isEnvProductionProfile,
|
|
283
|
+ keep_fnames: isEnvProductionProfile,
|
|
284
|
+ output: {
|
|
285
|
+ ecma: 5,
|
|
286
|
+ comments: false,
|
|
287
|
+ // Turned on because emoji and regex is not minified properly using default
|
|
288
|
+ // https://github.com/facebook/create-react-app/issues/2488
|
|
289
|
+ ascii_only: true,
|
|
290
|
+ },
|
|
291
|
+ },
|
|
292
|
+ }),
|
|
293
|
+ // This is only used in production mode
|
|
294
|
+ new CssMinimizerPlugin(),
|
|
295
|
+ ],
|
|
296
|
+ },
|
|
297
|
+ resolve: {
|
|
298
|
+ // This allows you to set a fallback for where webpack should look for modules.
|
|
299
|
+ // We placed these paths second because we want `node_modules` to "win"
|
|
300
|
+ // if there are any conflicts. This matches Node resolution mechanism.
|
|
301
|
+ // https://github.com/facebook/create-react-app/issues/253
|
|
302
|
+ modules: ['node_modules', paths.appNodeModules].concat(
|
|
303
|
+ modules.additionalModulePaths || []
|
|
304
|
+ ),
|
|
305
|
+ // These are the reasonable defaults supported by the Node ecosystem.
|
|
306
|
+ // We also include JSX as a common component filename extension to support
|
|
307
|
+ // some tools, although we do not recommend using it, see:
|
|
308
|
+ // https://github.com/facebook/create-react-app/issues/290
|
|
309
|
+ // `web` extension prefixes have been added for better support
|
|
310
|
+ // for React Native Web.
|
|
311
|
+ extensions: paths.moduleFileExtensions
|
|
312
|
+ .map(ext => `.${ext}`)
|
|
313
|
+ .filter(ext => useTypeScript || !ext.includes('ts')),
|
|
314
|
+ alias: {
|
|
315
|
+ // Support React Native Web
|
|
316
|
+ // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
|
|
317
|
+ 'react-native': 'react-native-web',
|
|
318
|
+ // Allows for better profiling with ReactDevTools
|
|
319
|
+ ...(isEnvProductionProfile && {
|
|
320
|
+ 'react-dom$': 'react-dom/profiling',
|
|
321
|
+ 'scheduler/tracing': 'scheduler/tracing-profiling',
|
|
322
|
+ }),
|
|
323
|
+ ...(modules.webpackAliases || {}),
|
|
324
|
+ '@': path.resolve('src'),
|
|
325
|
+ },
|
|
326
|
+ plugins: [
|
|
327
|
+ // Prevents users from importing files from outside of src/ (or node_modules/).
|
|
328
|
+ // This often causes confusion because we only process files within src/ with babel.
|
|
329
|
+ // To fix this, we prevent you from importing files out of src/ -- if you'd like to,
|
|
330
|
+ // please link the files into your node_modules/ and let module-resolution kick in.
|
|
331
|
+ // Make sure your source files are compiled, as they will not be processed in any way.
|
|
332
|
+ new ModuleScopePlugin(paths.appSrc, [
|
|
333
|
+ paths.appPackageJson,
|
|
334
|
+ reactRefreshRuntimeEntry,
|
|
335
|
+ reactRefreshWebpackPluginRuntimeEntry,
|
|
336
|
+ babelRuntimeEntry,
|
|
337
|
+ babelRuntimeEntryHelpers,
|
|
338
|
+ babelRuntimeRegenerator,
|
|
339
|
+ ]),
|
|
340
|
+ ],
|
|
341
|
+ },
|
|
342
|
+ module: {
|
|
343
|
+ strictExportPresence: true,
|
|
344
|
+ rules: [
|
|
345
|
+ // Handle node_modules packages that contain sourcemaps
|
|
346
|
+ shouldUseSourceMap && {
|
|
347
|
+ enforce: 'pre',
|
|
348
|
+ exclude: /@babel(?:\/|\\{1,2})runtime/,
|
|
349
|
+ test: /\.(js|mjs|jsx|ts|tsx|css)$/,
|
|
350
|
+ loader: require.resolve('source-map-loader'),
|
|
351
|
+ },
|
|
352
|
+ {
|
|
353
|
+ // "oneOf" will traverse all following loaders until one will
|
|
354
|
+ // match the requirements. When no loader matches it will fall
|
|
355
|
+ // back to the "file" loader at the end of the loader list.
|
|
356
|
+ oneOf: [
|
|
357
|
+ // TODO: Merge this config once `image/avif` is in the mime-db
|
|
358
|
+ // https://github.com/jshttp/mime-db
|
|
359
|
+ {
|
|
360
|
+ test: [/\.avif$/],
|
|
361
|
+ type: 'asset',
|
|
362
|
+ mimetype: 'image/avif',
|
|
363
|
+ parser: {
|
|
364
|
+ dataUrlCondition: {
|
|
365
|
+ maxSize: imageInlineSizeLimit,
|
|
366
|
+ },
|
|
367
|
+ },
|
|
368
|
+ },
|
|
369
|
+ // "url" loader works like "file" loader except that it embeds assets
|
|
370
|
+ // smaller than specified limit in bytes as data URLs to avoid requests.
|
|
371
|
+ // A missing `test` is equivalent to a match.
|
|
372
|
+ {
|
|
373
|
+ test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
|
|
374
|
+ type: 'asset',
|
|
375
|
+ parser: {
|
|
376
|
+ dataUrlCondition: {
|
|
377
|
+ maxSize: imageInlineSizeLimit,
|
|
378
|
+ },
|
|
379
|
+ },
|
|
380
|
+ },
|
|
381
|
+ {
|
|
382
|
+ test: /\.svg$/,
|
|
383
|
+ use: [
|
|
384
|
+ {
|
|
385
|
+ loader: require.resolve('@svgr/webpack'),
|
|
386
|
+ options: {
|
|
387
|
+ prettier: false,
|
|
388
|
+ svgo: false,
|
|
389
|
+ svgoConfig: {
|
|
390
|
+ plugins: [{ removeViewBox: false }],
|
|
391
|
+ },
|
|
392
|
+ titleProp: true,
|
|
393
|
+ ref: true,
|
|
394
|
+ },
|
|
395
|
+ },
|
|
396
|
+ {
|
|
397
|
+ loader: require.resolve('file-loader'),
|
|
398
|
+ options: {
|
|
399
|
+ name: 'static/media/[name].[hash].[ext]',
|
|
400
|
+ },
|
|
401
|
+ },
|
|
402
|
+ ],
|
|
403
|
+ issuer: {
|
|
404
|
+ and: [/\.(ts|tsx|js|jsx|md|mdx)$/],
|
|
405
|
+ },
|
|
406
|
+ },
|
|
407
|
+ // Process application JS with Babel.
|
|
408
|
+ // The preset includes JSX, Flow, TypeScript, and some ESnext features.
|
|
409
|
+ {
|
|
410
|
+ test: /\.(js|mjs|jsx|ts|tsx)$/,
|
|
411
|
+ include: paths.appSrc,
|
|
412
|
+ loader: require.resolve('babel-loader'),
|
|
413
|
+ options: {
|
|
414
|
+ customize: require.resolve(
|
|
415
|
+ 'babel-preset-react-app/webpack-overrides'
|
|
416
|
+ ),
|
|
417
|
+ presets: [
|
|
418
|
+ [
|
|
419
|
+ require.resolve('babel-preset-react-app'),
|
|
420
|
+ {
|
|
421
|
+ runtime: hasJsxRuntime ? 'automatic' : 'classic',
|
|
422
|
+ },
|
|
423
|
+ ],
|
|
424
|
+ ],
|
|
425
|
+
|
|
426
|
+ plugins: [
|
|
427
|
+ isEnvDevelopment &&
|
|
428
|
+ shouldUseReactRefresh &&
|
|
429
|
+ require.resolve('react-refresh/babel'),
|
|
430
|
+ ].filter(Boolean),
|
|
431
|
+ // This is a feature of `babel-loader` for webpack (not Babel itself).
|
|
432
|
+ // It enables caching results in ./node_modules/.cache/babel-loader/
|
|
433
|
+ // directory for faster rebuilds.
|
|
434
|
+ cacheDirectory: true,
|
|
435
|
+ // See #6846 for context on why cacheCompression is disabled
|
|
436
|
+ cacheCompression: false,
|
|
437
|
+ compact: isEnvProduction,
|
|
438
|
+ },
|
|
439
|
+ },
|
|
440
|
+ // Process any JS outside of the app with Babel.
|
|
441
|
+ // Unlike the application JS, we only compile the standard ES features.
|
|
442
|
+ {
|
|
443
|
+ test: /\.(js|mjs)$/,
|
|
444
|
+ exclude: /@babel(?:\/|\\{1,2})runtime/,
|
|
445
|
+ loader: require.resolve('babel-loader'),
|
|
446
|
+ options: {
|
|
447
|
+ babelrc: false,
|
|
448
|
+ configFile: false,
|
|
449
|
+ compact: false,
|
|
450
|
+ presets: [
|
|
451
|
+ [
|
|
452
|
+ require.resolve('babel-preset-react-app/dependencies'),
|
|
453
|
+ { helpers: true },
|
|
454
|
+ ],
|
|
455
|
+ ],
|
|
456
|
+ cacheDirectory: true,
|
|
457
|
+ // See #6846 for context on why cacheCompression is disabled
|
|
458
|
+ cacheCompression: false,
|
|
459
|
+
|
|
460
|
+ // Babel sourcemaps are needed for debugging into node_modules
|
|
461
|
+ // code. Without the options below, debuggers like VSCode
|
|
462
|
+ // show incorrect code and set breakpoints on the wrong lines.
|
|
463
|
+ sourceMaps: shouldUseSourceMap,
|
|
464
|
+ inputSourceMap: shouldUseSourceMap,
|
|
465
|
+ },
|
|
466
|
+ },
|
|
467
|
+ // "postcss" loader applies autoprefixer to our CSS.
|
|
468
|
+ // "css" loader resolves paths in CSS and adds assets as dependencies.
|
|
469
|
+ // "style" loader turns CSS into JS modules that inject <style> tags.
|
|
470
|
+ // In production, we use MiniCSSExtractPlugin to extract that CSS
|
|
471
|
+ // to a file, but in development "style" loader enables hot editing
|
|
472
|
+ // of CSS.
|
|
473
|
+ // By default we support CSS Modules with the extension .module.css
|
|
474
|
+ {
|
|
475
|
+ test: cssRegex,
|
|
476
|
+ exclude: cssModuleRegex,
|
|
477
|
+ use: getStyleLoaders({
|
|
478
|
+ importLoaders: 1,
|
|
479
|
+ sourceMap: isEnvProduction
|
|
480
|
+ ? shouldUseSourceMap
|
|
481
|
+ : isEnvDevelopment,
|
|
482
|
+ modules: {
|
|
483
|
+ mode: 'icss',
|
|
484
|
+ },
|
|
485
|
+ }),
|
|
486
|
+ // Don't consider CSS imports dead code even if the
|
|
487
|
+ // containing package claims to have no side effects.
|
|
488
|
+ // Remove this when webpack adds a warning or an error for this.
|
|
489
|
+ // See https://github.com/webpack/webpack/issues/6571
|
|
490
|
+ sideEffects: true,
|
|
491
|
+ },
|
|
492
|
+ // Adds support for CSS Modules (https://github.com/css-modules/css-modules)
|
|
493
|
+ // using the extension .module.css
|
|
494
|
+ {
|
|
495
|
+ test: cssModuleRegex,
|
|
496
|
+ use: getStyleLoaders({
|
|
497
|
+ importLoaders: 1,
|
|
498
|
+ sourceMap: isEnvProduction
|
|
499
|
+ ? shouldUseSourceMap
|
|
500
|
+ : isEnvDevelopment,
|
|
501
|
+ modules: {
|
|
502
|
+ mode: 'local',
|
|
503
|
+ getLocalIdent: getCSSModuleLocalIdent,
|
|
504
|
+ },
|
|
505
|
+ }),
|
|
506
|
+ },
|
|
507
|
+ // Opt-in support for SASS (using .scss or .sass extensions).
|
|
508
|
+ // By default we support SASS Modules with the
|
|
509
|
+ // extensions .module.scss or .module.sass
|
|
510
|
+ {
|
|
511
|
+ test: sassRegex,
|
|
512
|
+ exclude: sassModuleRegex,
|
|
513
|
+ use: getStyleLoaders(
|
|
514
|
+ {
|
|
515
|
+ importLoaders: 3,
|
|
516
|
+ sourceMap: isEnvProduction
|
|
517
|
+ ? shouldUseSourceMap
|
|
518
|
+ : isEnvDevelopment,
|
|
519
|
+ modules: {
|
|
520
|
+ mode: 'icss',
|
|
521
|
+ },
|
|
522
|
+ },
|
|
523
|
+ 'sass-loader'
|
|
524
|
+ ),
|
|
525
|
+ // Don't consider CSS imports dead code even if the
|
|
526
|
+ // containing package claims to have no side effects.
|
|
527
|
+ // Remove this when webpack adds a warning or an error for this.
|
|
528
|
+ // See https://github.com/webpack/webpack/issues/6571
|
|
529
|
+ sideEffects: true,
|
|
530
|
+ },
|
|
531
|
+ {
|
|
532
|
+ test: lessRegex,
|
|
533
|
+ exclude: lessModuleRegex,
|
|
534
|
+ use: getStyleLoaders({
|
|
535
|
+ importLoaders: 2,
|
|
536
|
+ sourceMap: isEnvProduction && shouldUseSourceMap,
|
|
537
|
+ },
|
|
538
|
+ 'less-loader'
|
|
539
|
+ ),
|
|
540
|
+ sideEffects: true,
|
|
541
|
+ },
|
|
542
|
+ {
|
|
543
|
+ test: lessModuleRegex,
|
|
544
|
+ use: getStyleLoaders({
|
|
545
|
+ importLoaders: 2,
|
|
546
|
+ modules: true,
|
|
547
|
+ getLocalIdent: getCSSModuleLocalIdent,
|
|
548
|
+ sourceMap: isEnvProduction && shouldUseSourceMap,
|
|
549
|
+ },
|
|
550
|
+ 'less-loader'
|
|
551
|
+ ),
|
|
552
|
+ },
|
|
553
|
+
|
|
554
|
+ // Adds support for CSS Modules, but using SASS
|
|
555
|
+ // using the extension .module.scss or .module.sass
|
|
556
|
+ {
|
|
557
|
+ test: sassModuleRegex,
|
|
558
|
+ use: getStyleLoaders(
|
|
559
|
+ {
|
|
560
|
+ importLoaders: 3,
|
|
561
|
+ sourceMap: isEnvProduction
|
|
562
|
+ ? shouldUseSourceMap
|
|
563
|
+ : isEnvDevelopment,
|
|
564
|
+ modules: {
|
|
565
|
+ mode: 'local',
|
|
566
|
+ getLocalIdent: getCSSModuleLocalIdent,
|
|
567
|
+ },
|
|
568
|
+ },
|
|
569
|
+ 'sass-loader'
|
|
570
|
+ ),
|
|
571
|
+ },
|
|
572
|
+ {
|
|
573
|
+ test: lessRegex,
|
|
574
|
+ exclude: lessModuleRegex,
|
|
575
|
+ use: getStyleLoaders({
|
|
576
|
+ importLoaders: 1,
|
|
577
|
+ modules: true,
|
|
578
|
+ sourceMap: isEnvProduction && shouldUseSourceMap
|
|
579
|
+ },
|
|
580
|
+ "less-loader"
|
|
581
|
+ ),
|
|
582
|
+ sideEffects: true
|
|
583
|
+ },
|
|
584
|
+ {
|
|
585
|
+ test: lessModuleRegex,
|
|
586
|
+ use: getStyleLoaders({
|
|
587
|
+ importLoaders: 1,
|
|
588
|
+ sourceMap: isEnvProduction && shouldUseSourceMap,
|
|
589
|
+ modules: true,
|
|
590
|
+ getLocalIdent: getCSSModuleLocalIdent
|
|
591
|
+ },
|
|
592
|
+ "less-loader"
|
|
593
|
+ )
|
|
594
|
+ },
|
|
595
|
+ // "file" loader makes sure those assets get served by WebpackDevServer.
|
|
596
|
+ // When you `import` an asset, you get its (virtual) filename.
|
|
597
|
+ // In production, they would get copied to the `build` folder.
|
|
598
|
+ // This loader doesn't use a "test" so it will catch all modules
|
|
599
|
+ // that fall through the other loaders.
|
|
600
|
+ {
|
|
601
|
+ // Exclude `js` files to keep "css" loader working as it injects
|
|
602
|
+ // its runtime that would otherwise be processed through "file" loader.
|
|
603
|
+ // Also exclude `html` and `json` extensions so they get processed
|
|
604
|
+ // by webpacks internal loaders.
|
|
605
|
+ exclude: [/^$/, /\.(js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/],
|
|
606
|
+ type: 'asset/resource',
|
|
607
|
+ },
|
|
608
|
+ // ** STOP ** Are you adding a new loader?
|
|
609
|
+ // Make sure to add the new loader(s) before the "file" loader.
|
|
610
|
+ ],
|
|
611
|
+ },
|
|
612
|
+ ].filter(Boolean),
|
|
613
|
+ },
|
|
614
|
+ plugins: [
|
|
615
|
+ // Generates an `index.html` file with the <script> injected.
|
|
616
|
+ new HtmlWebpackPlugin(
|
|
617
|
+ Object.assign(
|
|
618
|
+ {},
|
|
619
|
+ {
|
|
620
|
+ inject: true,
|
|
621
|
+ template: paths.appHtml,
|
|
622
|
+ },
|
|
623
|
+ isEnvProduction
|
|
624
|
+ ? {
|
|
625
|
+ minify: {
|
|
626
|
+ removeComments: true,
|
|
627
|
+ collapseWhitespace: true,
|
|
628
|
+ removeRedundantAttributes: true,
|
|
629
|
+ useShortDoctype: true,
|
|
630
|
+ removeEmptyAttributes: true,
|
|
631
|
+ removeStyleLinkTypeAttributes: true,
|
|
632
|
+ keepClosingSlash: true,
|
|
633
|
+ minifyJS: true,
|
|
634
|
+ minifyCSS: true,
|
|
635
|
+ minifyURLs: true,
|
|
636
|
+ },
|
|
637
|
+ }
|
|
638
|
+ : undefined
|
|
639
|
+ )
|
|
640
|
+ ),
|
|
641
|
+ // Inlines the webpack runtime script. This script is too small to warrant
|
|
642
|
+ // a network request.
|
|
643
|
+ // https://github.com/facebook/create-react-app/issues/5358
|
|
644
|
+ isEnvProduction &&
|
|
645
|
+ shouldInlineRuntimeChunk &&
|
|
646
|
+ new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/runtime-.+[.]js/]),
|
|
647
|
+ // Makes some environment variables available in index.html.
|
|
648
|
+ // The public URL is available as %PUBLIC_URL% in index.html, e.g.:
|
|
649
|
+ // <link rel="icon" href="%PUBLIC_URL%/favicon.ico">
|
|
650
|
+ // It will be an empty string unless you specify "homepage"
|
|
651
|
+ // in `package.json`, in which case it will be the pathname of that URL.
|
|
652
|
+ new InterpolateHtmlPlugin(HtmlWebpackPlugin, env.raw),
|
|
653
|
+ // This gives some necessary context to module not found errors, such as
|
|
654
|
+ // the requesting resource.
|
|
655
|
+ new ModuleNotFoundPlugin(paths.appPath),
|
|
656
|
+ // Makes some environment variables available to the JS code, for example:
|
|
657
|
+ // if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.
|
|
658
|
+ // It is absolutely essential that NODE_ENV is set to production
|
|
659
|
+ // during a production build.
|
|
660
|
+ // Otherwise React will be compiled in the very slow development mode.
|
|
661
|
+ new webpack.DefinePlugin(env.stringified),
|
|
662
|
+ // Experimental hot reloading for React .
|
|
663
|
+ // https://github.com/facebook/react/tree/main/packages/react-refresh
|
|
664
|
+ isEnvDevelopment &&
|
|
665
|
+ shouldUseReactRefresh &&
|
|
666
|
+ new ReactRefreshWebpackPlugin({
|
|
667
|
+ overlay: false,
|
|
668
|
+ }),
|
|
669
|
+ // Watcher doesn't work well if you mistype casing in a path so we use
|
|
670
|
+ // a plugin that prints an error when you attempt to do this.
|
|
671
|
+ // See https://github.com/facebook/create-react-app/issues/240
|
|
672
|
+ isEnvDevelopment && new CaseSensitivePathsPlugin(),
|
|
673
|
+ isEnvProduction &&
|
|
674
|
+ new MiniCssExtractPlugin({
|
|
675
|
+ // Options similar to the same options in webpackOptions.output
|
|
676
|
+ // both options are optional
|
|
677
|
+ filename: 'static/css/[name].[contenthash:8].css',
|
|
678
|
+ chunkFilename: 'static/css/[name].[contenthash:8].chunk.css',
|
|
679
|
+ }),
|
|
680
|
+ // Generate an asset manifest file with the following content:
|
|
681
|
+ // - "files" key: Mapping of all asset filenames to their corresponding
|
|
682
|
+ // output file so that tools can pick it up without having to parse
|
|
683
|
+ // `index.html`
|
|
684
|
+ // - "entrypoints" key: Array of files which are included in `index.html`,
|
|
685
|
+ // can be used to reconstruct the HTML if necessary
|
|
686
|
+ new WebpackManifestPlugin({
|
|
687
|
+ fileName: 'asset-manifest.json',
|
|
688
|
+ publicPath: paths.publicUrlOrPath,
|
|
689
|
+ generate: (seed, files, entrypoints) => {
|
|
690
|
+ const manifestFiles = files.reduce((manifest, file) => {
|
|
691
|
+ manifest[file.name] = file.path;
|
|
692
|
+ return manifest;
|
|
693
|
+ }, seed);
|
|
694
|
+ const entrypointFiles = entrypoints.main.filter(
|
|
695
|
+ fileName => !fileName.endsWith('.map')
|
|
696
|
+ );
|
|
697
|
+
|
|
698
|
+ return {
|
|
699
|
+ files: manifestFiles,
|
|
700
|
+ entrypoints: entrypointFiles,
|
|
701
|
+ };
|
|
702
|
+ },
|
|
703
|
+ }),
|
|
704
|
+ // Moment.js is an extremely popular library that bundles large locale files
|
|
705
|
+ // by default due to how webpack interprets its code. This is a practical
|
|
706
|
+ // solution that requires the user to opt into importing specific locales.
|
|
707
|
+ // https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
|
|
708
|
+ // You can remove this if you don't use Moment.js:
|
|
709
|
+ new webpack.IgnorePlugin({
|
|
710
|
+ resourceRegExp: /^\.\/locale$/,
|
|
711
|
+ contextRegExp: /moment$/,
|
|
712
|
+ }),
|
|
713
|
+ // Generate a service worker script that will precache, and keep up to date,
|
|
714
|
+ // the HTML & assets that are part of the webpack build.
|
|
715
|
+ isEnvProduction &&
|
|
716
|
+ fs.existsSync(swSrc) &&
|
|
717
|
+ new WorkboxWebpackPlugin.InjectManifest({
|
|
718
|
+ swSrc,
|
|
719
|
+ dontCacheBustURLsMatching: /\.[0-9a-f]{8}\./,
|
|
720
|
+ exclude: [/\.map$/, /asset-manifest\.json$/, /LICENSE/],
|
|
721
|
+ // Bump up the default maximum size (2mb) that's precached,
|
|
722
|
+ // to make lazy-loading failure scenarios less likely.
|
|
723
|
+ // See https://github.com/cra-template/pwa/issues/13#issuecomment-722667270
|
|
724
|
+ maximumFileSizeToCacheInBytes: 5 * 1024 * 1024,
|
|
725
|
+ }),
|
|
726
|
+ // TypeScript type checking
|
|
727
|
+ useTypeScript &&
|
|
728
|
+ new ForkTsCheckerWebpackPlugin({
|
|
729
|
+ async: isEnvDevelopment,
|
|
730
|
+ typescript: {
|
|
731
|
+ typescriptPath: resolve.sync('typescript', {
|
|
732
|
+ basedir: paths.appNodeModules,
|
|
733
|
+ }),
|
|
734
|
+ configOverwrite: {
|
|
735
|
+ compilerOptions: {
|
|
736
|
+ sourceMap: isEnvProduction
|
|
737
|
+ ? shouldUseSourceMap
|
|
738
|
+ : isEnvDevelopment,
|
|
739
|
+ skipLibCheck: true,
|
|
740
|
+ inlineSourceMap: false,
|
|
741
|
+ declarationMap: false,
|
|
742
|
+ noEmit: true,
|
|
743
|
+ incremental: true,
|
|
744
|
+ tsBuildInfoFile: paths.appTsBuildInfoFile,
|
|
745
|
+ },
|
|
746
|
+ },
|
|
747
|
+ context: paths.appPath,
|
|
748
|
+ diagnosticOptions: {
|
|
749
|
+ syntactic: true,
|
|
750
|
+ },
|
|
751
|
+ mode: 'write-references',
|
|
752
|
+ // profile: true,
|
|
753
|
+ },
|
|
754
|
+ issue: {
|
|
755
|
+ // This one is specifically to match during CI tests,
|
|
756
|
+ // as micromatch doesn't match
|
|
757
|
+ // '../cra-template-typescript/template/src/App.tsx'
|
|
758
|
+ // otherwise.
|
|
759
|
+ include: [
|
|
760
|
+ { file: '../**/src/**/*.{ts,tsx}' },
|
|
761
|
+ { file: '**/src/**/*.{ts,tsx}' },
|
|
762
|
+ ],
|
|
763
|
+ exclude: [
|
|
764
|
+ { file: '**/src/**/__tests__/**' },
|
|
765
|
+ { file: '**/src/**/?(*.){spec|test}.*' },
|
|
766
|
+ { file: '**/src/setupProxy.*' },
|
|
767
|
+ { file: '**/src/setupTests.*' },
|
|
768
|
+ ],
|
|
769
|
+ },
|
|
770
|
+ logger: {
|
|
771
|
+ infrastructure: 'silent',
|
|
772
|
+ },
|
|
773
|
+ }),
|
|
774
|
+ !disableESLintPlugin &&
|
|
775
|
+ new ESLintPlugin({
|
|
776
|
+ // Plugin options
|
|
777
|
+ extensions: ['js', 'mjs', 'jsx', 'ts', 'tsx'],
|
|
778
|
+ formatter: require.resolve('react-dev-utils/eslintFormatter'),
|
|
779
|
+ eslintPath: require.resolve('eslint'),
|
|
780
|
+ failOnError: !(isEnvDevelopment && emitErrorsAsWarnings),
|
|
781
|
+ context: paths.appSrc,
|
|
782
|
+ cache: true,
|
|
783
|
+ cacheLocation: path.resolve(
|
|
784
|
+ paths.appNodeModules,
|
|
785
|
+ '.cache/.eslintcache'
|
|
786
|
+ ),
|
|
787
|
+ // ESLint class options
|
|
788
|
+ cwd: paths.appPath,
|
|
789
|
+ resolvePluginsRelativeTo: __dirname,
|
|
790
|
+ baseConfig: {
|
|
791
|
+ extends: [require.resolve('eslint-config-react-app/base')],
|
|
792
|
+ rules: {
|
|
793
|
+ ...(!hasJsxRuntime && {
|
|
794
|
+ 'react/react-in-jsx-scope': 'error',
|
|
795
|
+ }),
|
|
796
|
+ },
|
|
797
|
+ },
|
|
798
|
+ }),
|
|
799
|
+ ].filter(Boolean),
|
|
800
|
+ // Turn off performance processing because we utilize
|
|
801
|
+ // our own hints via the FileSizeReporter
|
|
802
|
+ performance: false,
|
|
803
|
+ };
|
|
804
|
+};
|