1. 'use strict';
    
  2. 
    
  3. // Fork Start
    
  4. const ReactFlightWebpackPlugin = require('react-server-dom-webpack/plugin');
    
  5. // Fork End
    
  6. 
    
  7. const fs = require('fs');
    
  8. const {createHash} = require('crypto');
    
  9. const path = require('path');
    
  10. const webpack = require('webpack');
    
  11. const resolve = require('resolve');
    
  12. const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
    
  13. const TerserPlugin = require('terser-webpack-plugin');
    
  14. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
    
  15. const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
    
  16. const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
    
  17. const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent');
    
  18. const paths = require('./paths');
    
  19. const modules = require('./modules');
    
  20. const getClientEnvironment = require('./env');
    
  21. const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
    
  22. const ForkTsCheckerWebpackPlugin =
    
  23.   process.env.TSC_COMPILE_ON_ERROR === 'true'
    
  24.     ? require('react-dev-utils/ForkTsCheckerWarningWebpackPlugin')
    
  25.     : require('react-dev-utils/ForkTsCheckerWebpackPlugin');
    
  26. const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
    
  27. const {WebpackManifestPlugin} = require('webpack-manifest-plugin');
    
  28. 
    
  29. function createEnvironmentHash(env) {
    
  30.   const hash = createHash('md5');
    
  31.   hash.update(JSON.stringify(env));
    
  32. 
    
  33.   return hash.digest('hex');
    
  34. }
    
  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(
    
  41.   '@pmmmwh/react-refresh-webpack-plugin'
    
  42. );
    
  43. const babelRuntimeEntry = require.resolve('babel-preset-react-app');
    
  44. const babelRuntimeEntryHelpers = require.resolve(
    
  45.   '@babel/runtime/helpers/esm/assertThisInitialized',
    
  46.   {paths: [babelRuntimeEntry]}
    
  47. );
    
  48. const babelRuntimeRegenerator = require.resolve('@babel/runtime/regenerator', {
    
  49.   paths: [babelRuntimeEntry],
    
  50. });
    
  51. 
    
  52. // Some apps do not need the benefits of saving a web request, so not inlining the chunk
    
  53. // makes for a smoother build process.
    
  54. const shouldInlineRuntimeChunk = process.env.INLINE_RUNTIME_CHUNK !== 'false';
    
  55. 
    
  56. const imageInlineSizeLimit = parseInt(
    
  57.   process.env.IMAGE_INLINE_SIZE_LIMIT || '10000'
    
  58. );
    
  59. 
    
  60. // Check if TypeScript is setup
    
  61. const useTypeScript = fs.existsSync(paths.appTsConfig);
    
  62. 
    
  63. // Check if Tailwind config exists
    
  64. const useTailwind = fs.existsSync(
    
  65.   path.join(paths.appPath, 'tailwind.config.js')
    
  66. );
    
  67. 
    
  68. // Get the path to the uncompiled service worker (if it exists).
    
  69. const swSrc = paths.swSrc;
    
  70. 
    
  71. // style files regexes
    
  72. const cssRegex = /\.css$/;
    
  73. const cssModuleRegex = /\.module\.css$/;
    
  74. const sassRegex = /\.(scss|sass)$/;
    
  75. const sassModuleRegex = /\.module\.(scss|sass)$/;
    
  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.       {
    
  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: isEnvProduction
    
  206.       ? [paths.appIndexJs]
    
  207.       : [
    
  208.           paths.appIndexJs,
    
  209.           // HMR client
    
  210.           'webpack-hot-middleware/client?path=/__webpack_hmr&timeout=20000',
    
  211.         ],
    
  212.     output: {
    
  213.       // The build folder.
    
  214.       path: paths.appBuild,
    
  215.       // Add /* filename */ comments to generated require()s in the output.
    
  216.       pathinfo: isEnvDevelopment,
    
  217.       // There will be one main bundle, and one file per asynchronous chunk.
    
  218.       // In development, it does not produce real files.
    
  219.       filename: isEnvProduction
    
  220.         ? 'static/js/[name].[contenthash:8].js'
    
  221.         : isEnvDevelopment && 'static/js/bundle.js',
    
  222.       // There are also additional JS chunk files if you use code splitting.
    
  223.       chunkFilename: isEnvProduction
    
  224.         ? 'static/js/[name].[contenthash:8].chunk.js'
    
  225.         : isEnvDevelopment && 'static/js/[name].chunk.js',
    
  226.       assetModuleFilename: 'static/media/[name].[hash][ext]',
    
  227.       // webpack uses `publicPath` to determine where the app is being served from.
    
  228.       // It requires a trailing slash, or the file assets will get an incorrect path.
    
  229.       // We inferred the "public path" (such as / or /my-project) from homepage.
    
  230.       publicPath: paths.publicUrlOrPath,
    
  231.       // Point sourcemap entries to original disk location (format as URL on Windows)
    
  232.       devtoolModuleFilenameTemplate: isEnvProduction
    
  233.         ? info =>
    
  234.             path
    
  235.               .relative(paths.appSrc, info.absoluteResourcePath)
    
  236.               .replace(/\\/g, '/')
    
  237.         : isEnvDevelopment &&
    
  238.           (info => path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')),
    
  239.     },
    
  240.     cache: {
    
  241.       type: 'filesystem',
    
  242.       version: createEnvironmentHash(env.raw),
    
  243.       cacheDirectory: paths.appWebpackCache,
    
  244.       store: 'pack',
    
  245.       buildDependencies: {
    
  246.         defaultWebpack: ['webpack/lib/'],
    
  247.         config: [__filename],
    
  248.         tsconfig: [paths.appTsConfig, paths.appJsConfig].filter(f =>
    
  249.           fs.existsSync(f)
    
  250.         ),
    
  251.       },
    
  252.     },
    
  253.     infrastructureLogging: {
    
  254.       level: 'none',
    
  255.     },
    
  256.     optimization: {
    
  257.       minimize: isEnvProduction,
    
  258.       minimizer: [
    
  259.         // This is only used in production mode
    
  260.         new TerserPlugin({
    
  261.           terserOptions: {
    
  262.             parse: {
    
  263.               // We want terser to parse ecma 8 code. However, we don't want it
    
  264.               // to apply any minification steps that turns valid ecma 5 code
    
  265.               // into invalid ecma 5 code. This is why the 'compress' and 'output'
    
  266.               // sections only apply transformations that are ecma 5 safe
    
  267.               // https://github.com/facebook/create-react-app/pull/4234
    
  268.               ecma: 8,
    
  269.             },
    
  270.             compress: {
    
  271.               ecma: 5,
    
  272.               warnings: false,
    
  273.               // Disabled because of an issue with Uglify breaking seemingly valid code:
    
  274.               // https://github.com/facebook/create-react-app/issues/2376
    
  275.               // Pending further investigation:
    
  276.               // https://github.com/mishoo/UglifyJS2/issues/2011
    
  277.               comparisons: false,
    
  278.               // Disabled because of an issue with Terser breaking valid code:
    
  279.               // https://github.com/facebook/create-react-app/issues/5250
    
  280.               // Pending further investigation:
    
  281.               // https://github.com/terser-js/terser/issues/120
    
  282.               inline: 2,
    
  283.             },
    
  284.             mangle: {
    
  285.               safari10: true,
    
  286.             },
    
  287.             // Added for profiling in devtools
    
  288.             keep_classnames: isEnvProductionProfile,
    
  289.             keep_fnames: isEnvProductionProfile,
    
  290.             output: {
    
  291.               ecma: 5,
    
  292.               comments: false,
    
  293.               // Turned on because emoji and regex is not minified properly using default
    
  294.               // https://github.com/facebook/create-react-app/issues/2488
    
  295.               ascii_only: true,
    
  296.             },
    
  297.           },
    
  298.         }),
    
  299.         // This is only used in production mode
    
  300.         new CssMinimizerPlugin(),
    
  301.       ],
    
  302.     },
    
  303.     resolve: {
    
  304.       // This allows you to set a fallback for where webpack should look for modules.
    
  305.       // We placed these paths second because we want `node_modules` to "win"
    
  306.       // if there are any conflicts. This matches Node resolution mechanism.
    
  307.       // https://github.com/facebook/create-react-app/issues/253
    
  308.       modules: ['node_modules', paths.appNodeModules].concat(
    
  309.         modules.additionalModulePaths || []
    
  310.       ),
    
  311.       // These are the reasonable defaults supported by the Node ecosystem.
    
  312.       // We also include JSX as a common component filename extension to support
    
  313.       // some tools, although we do not recommend using it, see:
    
  314.       // https://github.com/facebook/create-react-app/issues/290
    
  315.       // `web` extension prefixes have been added for better support
    
  316.       // for React Native Web.
    
  317.       extensions: paths.moduleFileExtensions
    
  318.         .map(ext => `.${ext}`)
    
  319.         .filter(ext => useTypeScript || !ext.includes('ts')),
    
  320.       alias: {
    
  321.         // Support React Native Web
    
  322.         // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
    
  323.         'react-native': 'react-native-web',
    
  324.         // Allows for better profiling with ReactDevTools
    
  325.         ...(isEnvProductionProfile && {
    
  326.           'react-dom$': 'react-dom/profiling',
    
  327.           'scheduler/tracing': 'scheduler/tracing-profiling',
    
  328.         }),
    
  329.         ...(modules.webpackAliases || {}),
    
  330.       },
    
  331.       plugins: [
    
  332.         // Prevents users from importing files from outside of src/ (or node_modules/).
    
  333.         // This often causes confusion because we only process files within src/ with babel.
    
  334.         // To fix this, we prevent you from importing files out of src/ -- if you'd like to,
    
  335.         // please link the files into your node_modules/ and let module-resolution kick in.
    
  336.         // Make sure your source files are compiled, as they will not be processed in any way.
    
  337.         new ModuleScopePlugin(paths.appSrc, [
    
  338.           paths.appPackageJson,
    
  339.           reactRefreshRuntimeEntry,
    
  340.           reactRefreshWebpackPluginRuntimeEntry,
    
  341.           babelRuntimeEntry,
    
  342.           babelRuntimeEntryHelpers,
    
  343.           babelRuntimeRegenerator,
    
  344.         ]),
    
  345.       ],
    
  346.     },
    
  347.     module: {
    
  348.       strictExportPresence: true,
    
  349.       rules: [
    
  350.         // Handle node_modules packages that contain sourcemaps
    
  351.         shouldUseSourceMap && {
    
  352.           enforce: 'pre',
    
  353.           exclude: /@babel(?:\/|\\{1,2})runtime/,
    
  354.           test: /\.(js|mjs|jsx|ts|tsx|css)$/,
    
  355.           loader: require.resolve('source-map-loader'),
    
  356.         },
    
  357.         {
    
  358.           // "oneOf" will traverse all following loaders until one will
    
  359.           // match the requirements. When no loader matches it will fall
    
  360.           // back to the "file" loader at the end of the loader list.
    
  361.           oneOf: [
    
  362.             // TODO: Merge this config once `image/avif` is in the mime-db
    
  363.             // https://github.com/jshttp/mime-db
    
  364.             {
    
  365.               test: [/\.avif$/],
    
  366.               type: 'asset',
    
  367.               mimetype: 'image/avif',
    
  368.               parser: {
    
  369.                 dataUrlCondition: {
    
  370.                   maxSize: imageInlineSizeLimit,
    
  371.                 },
    
  372.               },
    
  373.             },
    
  374.             // "url" loader works like "file" loader except that it embeds assets
    
  375.             // smaller than specified limit in bytes as data URLs to avoid requests.
    
  376.             // A missing `test` is equivalent to a match.
    
  377.             {
    
  378.               test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
    
  379.               type: 'asset',
    
  380.               parser: {
    
  381.                 dataUrlCondition: {
    
  382.                   maxSize: imageInlineSizeLimit,
    
  383.                 },
    
  384.               },
    
  385.             },
    
  386.             {
    
  387.               test: /\.svg$/,
    
  388.               use: [
    
  389.                 {
    
  390.                   loader: require.resolve('@svgr/webpack'),
    
  391.                   options: {
    
  392.                     prettier: false,
    
  393.                     svgo: false,
    
  394.                     svgoConfig: {
    
  395.                       plugins: [{removeViewBox: false}],
    
  396.                     },
    
  397.                     titleProp: true,
    
  398.                     ref: true,
    
  399.                   },
    
  400.                 },
    
  401.                 {
    
  402.                   loader: require.resolve('file-loader'),
    
  403.                   options: {
    
  404.                     name: 'static/media/[name].[hash].[ext]',
    
  405.                   },
    
  406.                 },
    
  407.               ],
    
  408.               issuer: {
    
  409.                 and: [/\.(ts|tsx|js|jsx|md|mdx)$/],
    
  410.               },
    
  411.             },
    
  412.             // Process application JS with Babel.
    
  413.             // The preset includes JSX, Flow, TypeScript, and some ESnext features.
    
  414.             {
    
  415.               test: /\.(js|mjs|jsx|ts|tsx)$/,
    
  416.               include: paths.appSrc,
    
  417.               loader: require.resolve('babel-loader'),
    
  418.               options: {
    
  419.                 customize: require.resolve(
    
  420.                   'babel-preset-react-app/webpack-overrides'
    
  421.                 ),
    
  422.                 presets: [
    
  423.                   [
    
  424.                     require.resolve('babel-preset-react-app'),
    
  425.                     {
    
  426.                       runtime: hasJsxRuntime ? 'automatic' : 'classic',
    
  427.                     },
    
  428.                   ],
    
  429.                 ],
    
  430. 
    
  431.                 plugins: [
    
  432.                   isEnvDevelopment &&
    
  433.                     shouldUseReactRefresh &&
    
  434.                     require.resolve('react-refresh/babel'),
    
  435.                 ].filter(Boolean),
    
  436.                 // This is a feature of `babel-loader` for webpack (not Babel itself).
    
  437.                 // It enables caching results in ./node_modules/.cache/babel-loader/
    
  438.                 // directory for faster rebuilds.
    
  439.                 cacheDirectory: true,
    
  440.                 // See #6846 for context on why cacheCompression is disabled
    
  441.                 cacheCompression: false,
    
  442.                 compact: isEnvProduction,
    
  443.               },
    
  444.             },
    
  445.             // Process any JS outside of the app with Babel.
    
  446.             // Unlike the application JS, we only compile the standard ES features.
    
  447.             {
    
  448.               test: /\.(js|mjs)$/,
    
  449.               exclude: /@babel(?:\/|\\{1,2})runtime/,
    
  450.               loader: require.resolve('babel-loader'),
    
  451.               options: {
    
  452.                 babelrc: false,
    
  453.                 configFile: false,
    
  454.                 compact: false,
    
  455.                 presets: [
    
  456.                   [
    
  457.                     require.resolve('babel-preset-react-app/dependencies'),
    
  458.                     {helpers: true},
    
  459.                   ],
    
  460.                 ],
    
  461.                 cacheDirectory: true,
    
  462.                 // See #6846 for context on why cacheCompression is disabled
    
  463.                 cacheCompression: false,
    
  464. 
    
  465.                 // Babel sourcemaps are needed for debugging into node_modules
    
  466.                 // code.  Without the options below, debuggers like VSCode
    
  467.                 // show incorrect code and set breakpoints on the wrong lines.
    
  468.                 sourceMaps: shouldUseSourceMap,
    
  469.                 inputSourceMap: shouldUseSourceMap,
    
  470.               },
    
  471.             },
    
  472.             // "postcss" loader applies autoprefixer to our CSS.
    
  473.             // "css" loader resolves paths in CSS and adds assets as dependencies.
    
  474.             // "style" loader turns CSS into JS modules that inject <style> tags.
    
  475.             // In production, we use MiniCSSExtractPlugin to extract that CSS
    
  476.             // to a file, but in development "style" loader enables hot editing
    
  477.             // of CSS.
    
  478.             // By default we support CSS Modules with the extension .module.css
    
  479.             {
    
  480.               test: cssRegex,
    
  481.               exclude: cssModuleRegex,
    
  482.               use: getStyleLoaders({
    
  483.                 importLoaders: 1,
    
  484.                 sourceMap: isEnvProduction
    
  485.                   ? shouldUseSourceMap
    
  486.                   : isEnvDevelopment,
    
  487.                 modules: {
    
  488.                   mode: 'icss',
    
  489.                 },
    
  490.               }),
    
  491.               // Don't consider CSS imports dead code even if the
    
  492.               // containing package claims to have no side effects.
    
  493.               // Remove this when webpack adds a warning or an error for this.
    
  494.               // See https://github.com/webpack/webpack/issues/6571
    
  495.               sideEffects: true,
    
  496.             },
    
  497.             // Adds support for CSS Modules (https://github.com/css-modules/css-modules)
    
  498.             // using the extension .module.css
    
  499.             {
    
  500.               test: cssModuleRegex,
    
  501.               use: getStyleLoaders({
    
  502.                 importLoaders: 1,
    
  503.                 sourceMap: isEnvProduction
    
  504.                   ? shouldUseSourceMap
    
  505.                   : isEnvDevelopment,
    
  506.                 modules: {
    
  507.                   mode: 'local',
    
  508.                   getLocalIdent: getCSSModuleLocalIdent,
    
  509.                 },
    
  510.               }),
    
  511.             },
    
  512.             // Opt-in support for SASS (using .scss or .sass extensions).
    
  513.             // By default we support SASS Modules with the
    
  514.             // extensions .module.scss or .module.sass
    
  515.             {
    
  516.               test: sassRegex,
    
  517.               exclude: sassModuleRegex,
    
  518.               use: getStyleLoaders(
    
  519.                 {
    
  520.                   importLoaders: 3,
    
  521.                   sourceMap: isEnvProduction
    
  522.                     ? shouldUseSourceMap
    
  523.                     : isEnvDevelopment,
    
  524.                   modules: {
    
  525.                     mode: 'icss',
    
  526.                   },
    
  527.                 },
    
  528.                 'sass-loader'
    
  529.               ),
    
  530.               // Don't consider CSS imports dead code even if the
    
  531.               // containing package claims to have no side effects.
    
  532.               // Remove this when webpack adds a warning or an error for this.
    
  533.               // See https://github.com/webpack/webpack/issues/6571
    
  534.               sideEffects: true,
    
  535.             },
    
  536.             // Adds support for CSS Modules, but using SASS
    
  537.             // using the extension .module.scss or .module.sass
    
  538.             {
    
  539.               test: sassModuleRegex,
    
  540.               use: getStyleLoaders(
    
  541.                 {
    
  542.                   importLoaders: 3,
    
  543.                   sourceMap: isEnvProduction
    
  544.                     ? shouldUseSourceMap
    
  545.                     : isEnvDevelopment,
    
  546.                   modules: {
    
  547.                     mode: 'local',
    
  548.                     getLocalIdent: getCSSModuleLocalIdent,
    
  549.                   },
    
  550.                 },
    
  551.                 'sass-loader'
    
  552.               ),
    
  553.             },
    
  554.             // "file" loader makes sure those assets get served by WebpackDevServer.
    
  555.             // When you `import` an asset, you get its (virtual) filename.
    
  556.             // In production, they would get copied to the `build` folder.
    
  557.             // This loader doesn't use a "test" so it will catch all modules
    
  558.             // that fall through the other loaders.
    
  559.             {
    
  560.               // Exclude `js` files to keep "css" loader working as it injects
    
  561.               // its runtime that would otherwise be processed through "file" loader.
    
  562.               // Also exclude `html` and `json` extensions so they get processed
    
  563.               // by webpacks internal loaders.
    
  564.               exclude: [/^$/, /\.(js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/],
    
  565.               type: 'asset/resource',
    
  566.             },
    
  567.             // ** STOP ** Are you adding a new loader?
    
  568.             // Make sure to add the new loader(s) before the "file" loader.
    
  569.           ],
    
  570.         },
    
  571.       ].filter(Boolean),
    
  572.     },
    
  573.     plugins: [
    
  574.       new webpack.HotModuleReplacementPlugin(),
    
  575.       // This gives some necessary context to module not found errors, such as
    
  576.       // the requesting resource.
    
  577.       new ModuleNotFoundPlugin(paths.appPath),
    
  578.       // Makes some environment variables available to the JS code, for example:
    
  579.       // if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.
    
  580.       // It is absolutely essential that NODE_ENV is set to production
    
  581.       // during a production build.
    
  582.       // Otherwise React will be compiled in the very slow development mode.
    
  583.       new webpack.DefinePlugin(env.stringified),
    
  584.       // Experimental hot reloading for React .
    
  585.       // https://github.com/facebook/react/tree/main/packages/react-refresh
    
  586.       isEnvDevelopment &&
    
  587.         shouldUseReactRefresh &&
    
  588.         new ReactRefreshWebpackPlugin({
    
  589.           overlay: false,
    
  590.         }),
    
  591.       // Watcher doesn't work well if you mistype casing in a path so we use
    
  592.       // a plugin that prints an error when you attempt to do this.
    
  593.       // See https://github.com/facebook/create-react-app/issues/240
    
  594.       isEnvDevelopment && new CaseSensitivePathsPlugin(),
    
  595.       new MiniCssExtractPlugin({
    
  596.         // Options similar to the same options in webpackOptions.output
    
  597.         // both options are optional
    
  598.         filename: 'static/css/[name].[contenthash:8].css',
    
  599.         chunkFilename: 'static/css/[name].[contenthash:8].chunk.css',
    
  600.       }),
    
  601.       // Generate a manifest containing the required script / css for each entry.
    
  602.       new WebpackManifestPlugin({
    
  603.         fileName: 'entrypoint-manifest.json',
    
  604.         publicPath: paths.publicUrlOrPath,
    
  605.         generate: (seed, files, entrypoints) => {
    
  606.           const entrypointFiles = entrypoints.main.filter(
    
  607.             fileName => !fileName.endsWith('.map')
    
  608.           );
    
  609. 
    
  610.           const processedEntrypoints = {};
    
  611.           for (let key in entrypoints) {
    
  612.             processedEntrypoints[key] = {
    
  613.               js: entrypoints[key].filter(
    
  614.                 filename =>
    
  615.                   // Include JS assets but ignore hot updates because they're not
    
  616.                   // safe to include as async script tags.
    
  617.                   filename.endsWith('.js') &&
    
  618.                   !filename.endsWith('.hot-update.js')
    
  619.               ),
    
  620.               css: entrypoints[key].filter(filename =>
    
  621.                 filename.endsWith('.css')
    
  622.               ),
    
  623.             };
    
  624.           }
    
  625. 
    
  626.           return processedEntrypoints;
    
  627.         },
    
  628.       }),
    
  629.       // Moment.js is an extremely popular library that bundles large locale files
    
  630.       // by default due to how webpack interprets its code. This is a practical
    
  631.       // solution that requires the user to opt into importing specific locales.
    
  632.       // https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
    
  633.       // You can remove this if you don't use Moment.js:
    
  634.       new webpack.IgnorePlugin({
    
  635.         resourceRegExp: /^\.\/locale$/,
    
  636.         contextRegExp: /moment$/,
    
  637.       }),
    
  638.       // TypeScript type checking
    
  639.       useTypeScript &&
    
  640.         new ForkTsCheckerWebpackPlugin({
    
  641.           async: isEnvDevelopment,
    
  642.           typescript: {
    
  643.             typescriptPath: resolve.sync('typescript', {
    
  644.               basedir: paths.appNodeModules,
    
  645.             }),
    
  646.             configOverwrite: {
    
  647.               compilerOptions: {
    
  648.                 sourceMap: isEnvProduction
    
  649.                   ? shouldUseSourceMap
    
  650.                   : isEnvDevelopment,
    
  651.                 skipLibCheck: true,
    
  652.                 inlineSourceMap: false,
    
  653.                 declarationMap: false,
    
  654.                 noEmit: true,
    
  655.                 incremental: true,
    
  656.                 tsBuildInfoFile: paths.appTsBuildInfoFile,
    
  657.               },
    
  658.             },
    
  659.             context: paths.appPath,
    
  660.             diagnosticOptions: {
    
  661.               syntactic: true,
    
  662.             },
    
  663.             mode: 'write-references',
    
  664.             // profile: true,
    
  665.           },
    
  666.           issue: {
    
  667.             // This one is specifically to match during CI tests,
    
  668.             // as micromatch doesn't match
    
  669.             // '../cra-template-typescript/template/src/App.tsx'
    
  670.             // otherwise.
    
  671.             include: [
    
  672.               {file: '../**/src/**/*.{ts,tsx}'},
    
  673.               {file: '**/src/**/*.{ts,tsx}'},
    
  674.             ],
    
  675.             exclude: [
    
  676.               {file: '**/src/**/__tests__/**'},
    
  677.               {file: '**/src/**/?(*.){spec|test}.*'},
    
  678.               {file: '**/src/setupProxy.*'},
    
  679.               {file: '**/src/setupTests.*'},
    
  680.             ],
    
  681.           },
    
  682.           logger: {
    
  683.             infrastructure: 'silent',
    
  684.           },
    
  685.         }),
    
  686.       // Fork Start
    
  687.       new ReactFlightWebpackPlugin({
    
  688.         isServer: false,
    
  689.         clientReferences: {
    
  690.           directory: './src',
    
  691.           recursive: true,
    
  692.           include: /\.(js|ts|jsx|tsx)$/,
    
  693.         },
    
  694.       }),
    
  695.       // Fork End
    
  696.     ].filter(Boolean),
    
  697.     experiments: {
    
  698.       topLevelAwait: true,
    
  699.     },
    
  700.     // Turn off performance processing because we utilize
    
  701.     // our own hints via the FileSizeReporter
    
  702.     performance: false,
    
  703.   };
    
  704. };