@@ -1,628 +0,0 @@
3−const fs = require('fs');
4−const isWsl = require('is-wsl');
5−const path = require('path');
6−const webpack = require('webpack');
7−const resolve = require('resolve');
8−const PnpWebpackPlugin = require('pnp-webpack-plugin');
9−const HtmlWebpackPlugin = require('html-webpack-plugin');
10−const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
11−const InlineChunkHtmlPlugin = require('react-dev-utils/InlineChunkHtmlPlugin');
12−const TerserPlugin = require('terser-webpack-plugin');
13−const MiniCssExtractPlugin = require('mini-css-extract-plugin');
14−const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
15−const safePostCssParser = require('postcss-safe-parser');
16−const ManifestPlugin = require('webpack-manifest-plugin');
17−const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
18−const WorkboxWebpackPlugin = require('workbox-webpack-plugin');
19−const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
20−const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
21−const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent');
22−const paths = require('./paths');
23−const modules = require('./modules');
24−const getClientEnvironment = require('./env');
25−const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
26−const ForkTsCheckerWebpackPlugin = require('react-dev-utils/ForkTsCheckerWebpackPlugin');
27−const typescriptFormatter = require('react-dev-utils/typescriptFormatter');
29−const postcssNormalize = require('postcss-normalize');
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−// Some apps do not need the benefits of saving a web request, so not inlining the chunk
34−// makes for a smoother build process.
35−const shouldInlineRuntimeChunk = process.env.INLINE_RUNTIME_CHUNK !== 'false';
37−// Check if TypeScript is setup
38−const useTypeScript = fs.existsSync(paths.appTsConfig);
40−// style files regexes
41−const cssRegex = /\.css$/;
42−const cssModuleRegex = /\.module\.css$/;
43−const sassRegex = /\.(scss|sass)$/;
44−const sassModuleRegex = /\.module\.(scss|sass)$/;
46−// This is the production and development configuration.
47−// It is focused on developer experience, fast rebuilds, and a minimal bundle.
48−module.exports = function(webpackEnv) {
49− const isEnvDevelopment = webpackEnv === 'development';
50− const isEnvProduction = webpackEnv === 'production';
52− // Webpack uses `publicPath` to determine where the app is being served from.
53− // It requires a trailing slash, or the file assets will get an incorrect path.
54− // In development, we always serve from the root. This makes config easier.
55− const publicPath = isEnvProduction
57− : isEnvDevelopment && '/';
58− // Some apps do not use client-side routing with pushState.
59− // For these, "homepage" can be set to "." to enable relative asset paths.
60− const shouldUseRelativeAssetPaths = publicPath === './';
62− // `publicUrl` is just like `publicPath`, but we will provide it to our app
63− // as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
64− // Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
65− const publicUrl = isEnvProduction
66− ? publicPath.slice(0, -1)
67− : isEnvDevelopment && '';
68− // Get environment variables to inject into our app.
69− const env = getClientEnvironment(publicUrl);
71− // common function to get style loaders
72− const getStyleLoaders = (cssOptions, preProcessor) => {
74− isEnvDevelopment && require.resolve('style-loader'),
76− loader: MiniCssExtractPlugin.loader,
77− options: shouldUseRelativeAssetPaths ? { publicPath: '../../' } : {},
80− loader: require.resolve('css-loader'),
84− // Options for PostCSS as we reference these options twice
85− // Adds vendor prefixing based on your specified browser support in
87− loader: require.resolve('postcss-loader'),
89− // Necessary for external CSS imports to work
90− // https://github.com/facebook/create-react-app/issues/2677
93− require('postcss-flexbugs-fixes'),
94− require('postcss-preset-env')({
100− // Adds PostCSS Normalize as the reset css with default options,
101− // so that it honors browserslist config in package.json
102− // which in turn let's users customize the target behavior as per their needs.
105− sourceMap: isEnvProduction && shouldUseSourceMap,
111− loader: require.resolve(preProcessor),
113− sourceMap: isEnvProduction && shouldUseSourceMap,
121− mode: isEnvProduction ? 'production' : isEnvDevelopment && 'development',
122− // Stop compilation early in production
123− bail: isEnvProduction,
124− devtool: isEnvProduction
125− ? shouldUseSourceMap
128− : isEnvDevelopment && 'cheap-module-source-map',
129− // These are the "entry points" to our application.
130− // This means they will be the "root" imports that are included in JS bundle.
132− // Include an alternative client for WebpackDevServer. A client's job is to
133− // connect to WebpackDevServer by a socket and get notified about changes.
134− // When you save a file, the client will either apply hot updates (in case
135− // of CSS changes), or refresh the page (in case of JS changes). When you
136− // make a syntax error, this client will display a syntax error overlay.
137− // Note: instead of the default WebpackDevServer client, we use a custom one
138− // to bring better experience for Create React App users. You can replace
139− // the line below with these two lines if you prefer the stock client:
140− // require.resolve('webpack-dev-server/client') + '?/',
141− // require.resolve('webpack/hot/dev-server'),
143− require.resolve('react-dev-utils/webpackHotDevClient'),
144− // Finally, this is your app's code:
146− // We include the app code last so that if there is a runtime error during
147− // initialization, it doesn't blow up the WebpackDevServer client, and
148− // changing JS code would still trigger a refresh.
151− // The build folder.
152− path: isEnvProduction ? paths.appBuild : undefined,
153− // Add /* filename */ comments to generated require()s in the output.
154− pathinfo: isEnvDevelopment,
155− // There will be one main bundle, and one file per asynchronous chunk.
156− // In development, it does not produce real files.
157− filename: isEnvProduction
158− ? 'static/js/[name].[contenthash:8].js'
159− : isEnvDevelopment && 'static/js/bundle.js',
160− // TODO: remove this when upgrading to webpack 5
161− futureEmitAssets: true,
162− // There are also additional JS chunk files if you use code splitting.
163− chunkFilename: isEnvProduction
164− ? 'static/js/[name].[contenthash:8].chunk.js'
165− : isEnvDevelopment && 'static/js/[name].chunk.js',
166− // We inferred the "public path" (such as / or /my-project) from homepage.
167− // We use "/" in development.
168− publicPath: publicPath,
169− // Point sourcemap entries to original disk location (format as URL on Windows)
170− devtoolModuleFilenameTemplate: isEnvProduction
173− .relative(paths.appSrc, info.absoluteResourcePath)
174− .replace(/\\/g, '/')
175− : isEnvDevelopment &&
176− (info => path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')),
179− minimize: isEnvProduction,
181− // This is only used in production mode
185− // we want terser to parse ecma 8 code. However, we don't want it
186− // to apply any minfication steps that turns valid ecma 5 code
187− // into invalid ecma 5 code. This is why the 'compress' and 'output'
188− // sections only apply transformations that are ecma 5 safe
189− // https://github.com/facebook/create-react-app/pull/4234
195− // Disabled because of an issue with Uglify breaking seemingly valid code:
196− // https://github.com/facebook/create-react-app/issues/2376
197− // Pending further investigation:
198− // https://github.com/mishoo/UglifyJS2/issues/2011
200− // Disabled because of an issue with Terser breaking valid code:
201− // https://github.com/facebook/create-react-app/issues/5250
202− // Pending futher investigation:
203− // https://github.com/terser-js/terser/issues/120
212− // Turned on because emoji and regex is not minified properly using default
213− // https://github.com/facebook/create-react-app/issues/2488
217− // Use multi-process parallel running to improve the build speed
218− // Default number of concurrent runs: os.cpus().length - 1
219− // Disabled on WSL (Windows Subsystem for Linux) due to an issue with Terser
220− // https://github.com/webpack-contrib/terser-webpack-plugin/issues/21
222− // Enable file caching
224− sourceMap: shouldUseSourceMap,
226− // This is only used in production mode
227− new OptimizeCSSAssetsPlugin({
228− cssProcessorOptions: {
229− parser: safePostCssParser,
230− map: shouldUseSourceMap
232− // `inline: false` forces the sourcemap to be output into a
235− // `annotation: true` appends the sourceMappingURL to the end of
236− // the css file, helping the browser find the sourcemap
243− // Automatically split vendor and commons
244− // https://twitter.com/wSokra/status/969633336732905474
245− // https://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366
250− // Keep the runtime chunk separated to enable long term caching
251− // https://twitter.com/wSokra/status/969679223278505985
255− // This allows you to set a fallback for where Webpack should look for modules.
256− // We placed these paths second because we want `node_modules` to "win"
257− // if there are any conflicts. This matches Node resolution mechanism.
258− // https://github.com/facebook/create-react-app/issues/253
259− modules: ['node_modules', paths.appNodeModules].concat(
260− modules.additionalModulePaths || []
262− // These are the reasonable defaults supported by the Node ecosystem.
263− // We also include JSX as a common component filename extension to support
264− // some tools, although we do not recommend using it, see:
265− // https://github.com/facebook/create-react-app/issues/290
266− // `web` extension prefixes have been added for better support
267− // for React Native Web.
268− extensions: paths.moduleFileExtensions
269− .map(ext => `.${ext}`)
270− .filter(ext => useTypeScript || !ext.includes('ts')),
272− // Support React Native Web
273− // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
274− 'react-native': 'react-native-web',
277− // Adds support for installing with Plug'n'Play, leading to faster installs and adding
278− // guards against forgotten dependencies and such.
280− // Prevents users from importing files from outside of src/ (or node_modules/).
281− // This often causes confusion because we only process files within src/ with babel.
282− // To fix this, we prevent you from importing files out of src/ -- if you'd like to,
283− // please link the files into your node_modules/ and let module-resolution kick in.
284− // Make sure your source files are compiled, as they will not be processed in any way.
285− new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]),
290− // Also related to Plug'n'Play, but this time it tells Webpack to load its loaders
291− // from the current package.
292− PnpWebpackPlugin.moduleLoader(module),
296− strictExportPresence: true,
298− // Disable require.ensure as it's not a standard language feature.
299− { parser: { requireEnsure: false } },
301− // First, run the linter.
302− // It's important to do this before Babel processes the JS.
304− test: /\.(js|mjs|jsx|ts|tsx)$/,
309− formatter: require.resolve('react-dev-utils/eslintFormatter'),
310− eslintPath: require.resolve('eslint'),
313− loader: require.resolve('eslint-loader'),
316− include: paths.appSrc,
319− // "oneOf" will traverse all following loaders until one will
320− // match the requirements. When no loader matches it will fall
321− // back to the "file" loader at the end of the loader list.
323− // "url" loader works like "file" loader except that it embeds assets
324− // smaller than specified limit in bytes as data URLs to avoid requests.
325− // A missing `test` is equivalent to a match.
327− test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
328− loader: require.resolve('url-loader'),
331− name: 'static/media/[name].[hash:8].[ext]',
334− // Process application JS with Babel.
335− // The preset includes JSX, Flow, TypeScript, and some ESnext features.
337− test: /\.(js|mjs|jsx|ts|tsx)$/,
338− include: paths.appSrc,
339− loader: require.resolve('babel-loader'),
341− customize: require.resolve(
342− 'babel-preset-react-app/webpack-overrides'
347− require.resolve('babel-plugin-named-asset-import'),
351− ReactComponent: '@svgr/webpack?-svgo,+ref![path]',
357− // This is a feature of `babel-loader` for webpack (not Babel itself).
358− // It enables caching results in ./node_modules/.cache/babel-loader/
359− // directory for faster rebuilds.
360− cacheDirectory: true,
361− cacheCompression: isEnvProduction,
362− compact: isEnvProduction,
365− // Process any JS outside of the app with Babel.
366− // Unlike the application JS, we only compile the standard ES features.
368− test: /\.(js|mjs)$/,
369− exclude: /@babel(?:\/|\\{1,2})runtime/,
370− loader: require.resolve('babel-loader'),
377− require.resolve('babel-preset-react-app/dependencies'),
381− cacheDirectory: true,
382− cacheCompression: isEnvProduction,
384− // If an error happens in a package, it's possible to be
385− // because it was compiled. Thus, we don't want the browser
386− // debugger to show the original code. Instead, the code
387− // being evaluated would be much more helpful.
391− // "postcss" loader applies autoprefixer to our CSS.
392− // "css" loader resolves paths in CSS and adds assets as dependencies.
393− // "style" loader turns CSS into JS modules that inject <style> tags.
394− // In production, we use MiniCSSExtractPlugin to extract that CSS
395− // to a file, but in development "style" loader enables hot editing
397− // By default we support CSS Modules with the extension .module.css
400− exclude: cssModuleRegex,
401− use: getStyleLoaders({
403− sourceMap: isEnvProduction && shouldUseSourceMap,
405− // Don't consider CSS imports dead code even if the
406− // containing package claims to have no side effects.
407− // Remove this when webpack adds a warning or an error for this.
408− // See https://github.com/webpack/webpack/issues/6571
411− // Adds support for CSS Modules (https://github.com/css-modules/css-modules)
412− // using the extension .module.css
414− test: cssModuleRegex,
415− use: getStyleLoaders({
417− sourceMap: isEnvProduction && shouldUseSourceMap,
419− getLocalIdent: getCSSModuleLocalIdent,
422− // Opt-in support for SASS (using .scss or .sass extensions).
423− // By default we support SASS Modules with the
424− // extensions .module.scss or .module.sass
427− exclude: sassModuleRegex,
428− use: getStyleLoaders(
431− sourceMap: isEnvProduction && shouldUseSourceMap,
435− // Don't consider CSS imports dead code even if the
436− // containing package claims to have no side effects.
437− // Remove this when webpack adds a warning or an error for this.
438− // See https://github.com/webpack/webpack/issues/6571
441− // Adds support for CSS Modules, but using SASS
442− // using the extension .module.scss or .module.sass
444− test: sassModuleRegex,
445− use: getStyleLoaders(
448− sourceMap: isEnvProduction && shouldUseSourceMap,
450− getLocalIdent: getCSSModuleLocalIdent,
455− // "file" loader makes sure those assets get served by WebpackDevServer.
456− // When you `import` an asset, you get its (virtual) filename.
457− // In production, they would get copied to the `build` folder.
458− // This loader doesn't use a "test" so it will catch all modules
459− // that fall through the other loaders.
461− loader: require.resolve('file-loader'),
462− // Exclude `js` files to keep "css" loader working as it injects
463− // its runtime that would otherwise be processed through "file" loader.
464− // Also exclude `html` and `json` extensions so they get processed
465− // by webpacks internal loaders.
466− exclude: [/\.(js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/],
468− name: 'static/media/[name].[hash:8].[ext]',
471− // ** STOP ** Are you adding a new loader?
472− // Make sure to add the new loader(s) before the "file" loader.
478− // Generates an `index.html` file with the <script> injected.
479− new HtmlWebpackPlugin(
484− template: paths.appHtml,
489− removeComments: true,
490− collapseWhitespace: true,
491− removeRedundantAttributes: true,
492− useShortDoctype: true,
493− removeEmptyAttributes: true,
494− removeStyleLinkTypeAttributes: true,
495− keepClosingSlash: true,
504− // Inlines the webpack runtime script. This script is too small to warrant
505− // a network request.
507− shouldInlineRuntimeChunk &&
508− new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/runtime~.+[.]js/]),
509− // Makes some environment variables available in index.html.
510− // The public URL is available as %PUBLIC_URL% in index.html, e.g.:
511− // <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
512− // In production, it will be an empty string unless you specify "homepage"
513− // in `package.json`, in which case it will be the pathname of that URL.
514− // In development, this will be an empty string.
515− new InterpolateHtmlPlugin(HtmlWebpackPlugin, env.raw),
516− // This gives some necessary context to module not found errors, such as
517− // the requesting resource.
518− new ModuleNotFoundPlugin(paths.appPath),
519− // Makes some environment variables available to the JS code, for example:
520− // if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.
521− // It is absolutely essential that NODE_ENV is set to production
522− // during a production build.
523− // Otherwise React will be compiled in the very slow development mode.
524− new webpack.DefinePlugin(env.stringified),
525− // This is necessary to emit hot updates (currently CSS only):
526− isEnvDevelopment && new webpack.HotModuleReplacementPlugin(),
527− // Watcher doesn't work well if you mistype casing in a path so we use
528− // a plugin that prints an error when you attempt to do this.
529− // See https://github.com/facebook/create-react-app/issues/240
530− isEnvDevelopment && new CaseSensitivePathsPlugin(),
531− // If you require a missing module and then `npm install` it, you still have
532− // to restart the development server for Webpack to discover it. This plugin
533− // makes the discovery automatic so you don't have to restart.
534− // See https://github.com/facebook/create-react-app/issues/186
536− new WatchMissingNodeModulesPlugin(paths.appNodeModules),
538− new MiniCssExtractPlugin({
539− // Options similar to the same options in webpackOptions.output
540− // both options are optional
541− filename: 'static/css/[name].[contenthash:8].css',
542− chunkFilename: 'static/css/[name].[contenthash:8].chunk.css',
544− // Generate a manifest file which contains a mapping of all asset filenames
545− // to their corresponding output file so that tools can pick it up without
546− // having to parse `index.html`.
547− new ManifestPlugin({
548− fileName: 'asset-manifest.json',
549− publicPath: publicPath,
550− generate: (seed, files) => {
551− const manifestFiles = files.reduce(function(manifest, file) {
552− manifest[file.name] = file.path;
557− files: manifestFiles,
561− // Moment.js is an extremely popular library that bundles large locale files
562− // by default due to how Webpack interprets its code. This is a practical
563− // solution that requires the user to opt into importing specific locales.
564− // https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
565− // You can remove this if you don't use Moment.js:
566− new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
567− // Generate a service worker script that will precache, and keep up to date,
568− // the HTML & assets that are part of the Webpack build.
570− new WorkboxWebpackPlugin.GenerateSW({
572− exclude: [/\.map$/, /asset-manifest\.json$/],
573− importWorkboxFrom: 'cdn',
574− navigateFallback: publicUrl + '/index.html',
575− navigateFallbackBlacklist: [
576− // Exclude URLs starting with /_, as they're likely an API call
578− // Exclude URLs containing a dot, as they're likely a resource in
579− // public/ and not a SPA route
580− new RegExp('/[^/]+\\.[^/]+$'),
583− // TypeScript type checking
585− new ForkTsCheckerWebpackPlugin({
586− typescript: resolve.sync('typescript', {
587− basedir: paths.appNodeModules,
589− async: isEnvDevelopment,
590− useTypescriptIncrementalApi: true,
591− checkSyntacticErrors: true,
592− resolveModuleNameModule: process.versions.pnp
593− ? `${__dirname}/pnpTs.js`
595− resolveTypeReferenceDirectiveModule: process.versions.pnp
596− ? `${__dirname}/pnpTs.js`
598− tsconfig: paths.appTsConfig,
602− '!**/?(*.)(spec|test).*',
603− '!**/src/setupProxy.*',
604− '!**/src/setupTests.*',
606− watch: paths.appSrc,
608− // The formatter is invoked directly in WebpackDevServerUtils during development
609− formatter: isEnvProduction ? typescriptFormatter : undefined,
612− // Some libraries import Node modules but don't use them in the browser.
613− // Tell Webpack to provide empty mocks for them so importing them works.
622− child_process: 'empty',
624− // Turn off performance processing because we utilize
625− // our own hints via the FileSizeReporter