gov-ui-core 0.2.6-beta.8 → 0.2.6

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