@xfe-repo/web-app 1.6.4 → 2.0.0-beta.2

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