@reactunity/scripts 0.8.1 → 0.10.0

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 (38) hide show
  1. package/README.md +2 -2
  2. package/bin/react-unity-scripts.js +6 -1
  3. package/config/env.js +2 -4
  4. package/config/eslint/base.js +43 -0
  5. package/config/eslint/config.js +252 -0
  6. package/config/eslint/jest.js +59 -0
  7. package/config/eslintConfig.js +2 -17
  8. package/config/jest/babelTransform.js +37 -0
  9. package/config/jest/cssTransform.js +22 -0
  10. package/config/jest/fileTransform.js +40 -0
  11. package/config/paths.js +9 -0
  12. package/config/{web-inspector → public}/.gitignore +0 -0
  13. package/config/{web-inspector → public}/favicon.ico +0 -0
  14. package/config/public/index.html +78 -0
  15. package/config/unityMiddleware.js +29 -0
  16. package/config/webpack/persistentCache/createEnvironmentHash.js +9 -0
  17. package/config/webpack.config.js +222 -116
  18. package/config/webpackDevServer.config.js +61 -81
  19. package/lib/types/base.d.ts +13 -2
  20. package/package.json +61 -52
  21. package/scripts/build.js +41 -19
  22. package/scripts/eject.js +237 -234
  23. package/scripts/init.js +15 -17
  24. package/scripts/lint.js +4 -3
  25. package/scripts/start.js +31 -40
  26. package/scripts/test.js +129 -0
  27. package/scripts/utils/createJestConfig.js +152 -0
  28. package/scripts/utils/verifyTypeScriptSetup.js +306 -309
  29. package/config/pnpTs.js +0 -43
  30. package/config/react-error-overlay.js +0 -9
  31. package/config/refreshOverlayInterop.js +0 -4
  32. package/config/web-inspector/Build/WebInspector.data +0 -0
  33. package/config/web-inspector/Build/WebInspector.framework.js +0 -7
  34. package/config/web-inspector/Build/WebInspector.loader.js +0 -1
  35. package/config/web-inspector/Build/WebInspector.wasm +0 -0
  36. package/config/web-inspector/index.html +0 -86
  37. package/config/webpackHotDevClient.js +0 -268
  38. package/scripts/utils/verifyPackageTree.js +0 -161
@@ -0,0 +1,29 @@
1
+ function registerUnityMiddleware(app) {
2
+ // Allow serving Unity builds
3
+ function contentEncodingShorthand(pattern, encoding) {
4
+ app.get(pattern, function (req, res, next) {
5
+ res.set('Content-Encoding', encoding);
6
+ next();
7
+ });
8
+ }
9
+
10
+ function contentTypeShorthand(pattern, type) {
11
+ app.get(pattern, function (req, res, next) {
12
+ res.set('Content-Type', type);
13
+ next();
14
+ });
15
+ }
16
+
17
+ contentEncodingShorthand('*.unityweb', 'gzip');
18
+ contentEncodingShorthand('*.gz', 'gzip');
19
+ contentEncodingShorthand('*.br', 'br');
20
+ contentTypeShorthand('*.js.gz', 'application/javascript');
21
+ contentTypeShorthand('*.js.br', 'application/javascript');
22
+ contentTypeShorthand('*.wasm', 'application/wasm');
23
+ contentTypeShorthand('*.wasm.gz', 'application/wasm');
24
+ contentTypeShorthand('*.wasm.br', 'application/wasm');
25
+ }
26
+
27
+ module.exports = {
28
+ registerUnityMiddleware,
29
+ };
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+ const { createHash } = require('crypto');
3
+
4
+ module.exports = env => {
5
+ const hash = createHash('md5');
6
+ hash.update(JSON.stringify(env));
7
+
8
+ return hash.digest('hex');
9
+ };
@@ -12,10 +12,10 @@ const fs = require('fs');
12
12
  const path = require('path');
13
13
  const webpack = require('webpack');
14
14
  const resolve = require('resolve');
15
- const PnpWebpackPlugin = require('pnp-webpack-plugin');
16
15
  const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
17
16
  const TerserPlugin = require('terser-webpack-plugin');
18
- const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
17
+ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
18
+ const { WebpackManifestPlugin } = require('webpack-manifest-plugin');
19
19
  const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
20
20
  const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent');
21
21
  const ESLintPlugin = require('eslint-webpack-plugin');
@@ -24,28 +24,43 @@ const paths = require('./paths');
24
24
  const modules = require('./modules');
25
25
  const getClientEnvironment = require('./env');
26
26
  const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
27
- const ForkTsCheckerWebpackPlugin = require('react-dev-utils/ForkTsCheckerWebpackPlugin');
28
- const typescriptFormatter = require('react-dev-utils/typescriptFormatter');
27
+ const ForkTsCheckerWebpackPlugin =
28
+ process.env.TSC_COMPILE_ON_ERROR === 'true'
29
+ ? require('react-dev-utils/ForkTsCheckerWarningWebpackPlugin')
30
+ : require('react-dev-utils/ForkTsCheckerWebpackPlugin');
29
31
  const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
30
- const restrictedGlobals = require('confusing-browser-globals');
31
32
  // @remove-on-eject-begin
32
33
  const getCacheIdentifier = require('react-dev-utils/getCacheIdentifier');
33
34
  // @remove-on-eject-end
34
-
35
+ const createEnvironmentHash = require('./webpack/persistentCache/createEnvironmentHash');
35
36
 
36
37
  // Source maps are resource heavy and can cause out of memory issue for large source files.
38
+
37
39
  const sourceMapVar = process.env.GENERATE_SOURCEMAP;
38
40
  const shouldUseSourceMap = sourceMapVar !== 'false' && !!sourceMapVar;
39
41
  const sourceMapType = sourceMapVar !== 'false' && sourceMapVar !== 'true' && sourceMapVar;
40
42
 
41
- const webpackDevClientEntry = require.resolve(
42
- './webpackHotDevClient'
43
+ const reactRefreshRuntimeEntry = require.resolve('react-refresh/runtime');
44
+ const reactRefreshWebpackPluginRuntimeEntry = require.resolve(
45
+ '@pmmmwh/react-refresh-webpack-plugin'
43
46
  );
44
- const reactRefreshOverlayEntry = require.resolve(
45
- './refreshOverlayInterop'
47
+ const babelRuntimeEntry = require.resolve('babel-preset-react-app');
48
+ const babelRuntimeEntryHelpers = require.resolve(
49
+ '@babel/runtime/helpers/esm/assertThisInitialized',
50
+ { paths: [babelRuntimeEntry] }
46
51
  );
52
+ const babelRuntimeRegenerator = require.resolve('@babel/runtime/regenerator', {
53
+ paths: [babelRuntimeEntry],
54
+ });
55
+
56
+ // Some apps do not need the benefits of saving a web request, so not inlining the chunk
57
+ // makes for a smoother build process.
58
+ const shouldInlineRuntimeChunk = process.env.INLINE_RUNTIME_CHUNK === 'true';
59
+
47
60
  const emitErrorsAsWarnings = process.env.ESLINT_NO_DEV_ERRORS === 'true';
48
61
  const disableESLintPlugin = process.env.DISABLE_ESLINT_PLUGIN === 'true';
62
+ const extractCss = process.env.EXTRACT_CSS === 'true';
63
+ const generateManifest = process.env.GENERATE_MANIFEST !== 'false';
49
64
 
50
65
  const imageInlineSizeLimit = parseInt(
51
66
  process.env.IMAGE_INLINE_SIZE_LIMIT || '0'
@@ -54,6 +69,25 @@ const imageInlineSizeLimit = parseInt(
54
69
  // Check if TypeScript is setup
55
70
  const useTypeScript = fs.existsSync(paths.appTsConfig);
56
71
 
72
+ // Check if Tailwind config exists
73
+ const useTailwind = fs.existsSync(
74
+ path.join(paths.appPath, 'tailwind.config.js')
75
+ );
76
+
77
+ const warnedAboutPlugin = {};
78
+ const usePostcssPluginIfExists = (name, options = {}) => {
79
+ try {
80
+ if (require.resolve(name)) {
81
+ if (!warnedAboutPlugin[name]) {
82
+ console.log('Using plugin ' + name);
83
+ warnedAboutPlugin[name] = true;
84
+ }
85
+ return { [name]: options };
86
+ }
87
+ } catch (err) { }
88
+ return {};
89
+ };
90
+
57
91
  // style files regexes
58
92
  const cssRegex = /\.css$/;
59
93
  const cssModuleRegex = /\.module\.css$/;
@@ -62,9 +96,10 @@ const sassModuleRegex = /\.module\.(scss|sass)$/;
62
96
 
63
97
  // This is the production and development configuration.
64
98
  // It is focused on developer experience, fast rebuilds, and a minimal bundle.
65
- module.exports = function (webpackEnv) {
99
+ const baseConfigFactory = function (webpackEnv) {
66
100
  const isEnvDevelopment = webpackEnv === 'development';
67
101
  const isEnvProduction = webpackEnv === 'production';
102
+ const shouldExtractCss = isEnvProduction && extractCss;
68
103
 
69
104
  // Variable used for enabling profiling in Production
70
105
  // passed into alias object. Uses a flag if passed into the build command
@@ -82,13 +117,41 @@ module.exports = function (webpackEnv) {
82
117
  // common function to get style loaders
83
118
  const getStyleLoaders = (cssOptions, preProcessor) => {
84
119
  const loaders = [
85
- // Always use style-loader in React Unity as we do not extract CSS files
86
- require.resolve('style-loader'),
87
-
120
+ !shouldExtractCss ? require.resolve('style-loader')
121
+ : {
122
+ loader: MiniCssExtractPlugin.loader,
123
+ // css is located in `static/css`, use '../../' to locate index.html folder
124
+ // in production `paths.publicUrlOrPath` can be a relative path
125
+ options: paths.publicUrlOrPath.startsWith('.')
126
+ ? { publicPath: '../../' }
127
+ : {},
128
+ },
88
129
  {
89
130
  loader: require.resolve('css-loader'),
90
131
  options: cssOptions,
91
132
  },
133
+ useTailwind && {
134
+ // Options for PostCSS as we reference these options twice
135
+ // Adds vendor prefixing based on your specified browser support in
136
+ // package.json
137
+ loader: require.resolve('postcss-loader'),
138
+ options: {
139
+ postcssOptions: {
140
+ // Necessary for external CSS imports to work
141
+ // https://github.com/facebook/create-react-app/issues/2677
142
+ ident: 'postcss',
143
+ config: false,
144
+ plugins: {
145
+ ...usePostcssPluginIfExists('postcss-import'),
146
+ 'tailwindcss': {},
147
+ ...usePostcssPluginIfExists('postcss-nesting'),
148
+ ...usePostcssPluginIfExists('postcss-custom-properties'),
149
+ ...usePostcssPluginIfExists('postcss-css-variables'),
150
+ },
151
+ },
152
+ sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
153
+ },
154
+ },
92
155
  ].filter(Boolean);
93
156
  if (preProcessor) {
94
157
  loaders.push(
@@ -121,40 +184,20 @@ module.exports = function (webpackEnv) {
121
184
  : isEnvDevelopment && (sourceMapType || 'eval-source-map'),
122
185
  // These are the "entry points" to our application.
123
186
  // This means they will be the "root" imports that are included in JS bundle.
124
- entry:
125
- isEnvDevelopment && !shouldUseReactRefresh
126
- ? [
127
- // Include an alternative client for WebpackDevServer. A client's job is to
128
- // connect to WebpackDevServer by a socket and get notified about changes.
129
- // When you save a file, the client will either apply hot updates (in case
130
- // of CSS changes), or refresh the page (in case of JS changes). When you
131
- // make a syntax error, this client will display a syntax error overlay.
132
- // Note: instead of the default WebpackDevServer client, we use a custom one
133
- // to bring better experience for Create React App users. You can replace
134
- // the line below with these two lines if you prefer the stock client:
135
- //
136
- // require.resolve('webpack-dev-server/client') + '?/',
137
- // require.resolve('webpack/hot/dev-server'),
138
- //
139
- // When using the experimental react-refresh integration,
140
- // the webpack plugin takes care of injecting the dev client for us.
141
- webpackDevClientEntry,
142
- // Finally, this is your app's code:
143
- paths.appIndexJs,
144
- // We include the app code last so that if there is a runtime error during
145
- // initialization, it doesn't blow up the WebpackDevServer client, and
146
- // changing JS code would still trigger a refresh.
147
- ]
148
- : paths.appIndexJs,
187
+ entry: paths.appIndexJs,
149
188
  output: {
150
189
  // The build folder.
151
- path: isEnvProduction ? paths.appBuild : undefined,
190
+ path: paths.appBuild,
152
191
  // Add /* filename */ comments to generated require()s in the output.
153
192
  pathinfo: isEnvDevelopment,
154
193
  // There will be one main bundle, and one file per asynchronous chunk.
155
194
  // In development, it does not produce real files.
156
195
  filename: isEnvDevelopment ? 'index.js' : process.env.FILENAME || 'index.js',
157
- chunkFilename: 'static/chunk/[name].js',
196
+ // There are also additional JS chunk files if you use code splitting.
197
+ chunkFilename: isEnvProduction
198
+ ? 'static/js/[name].chunk.js'
199
+ : isEnvDevelopment && 'static/js/[name].chunk.js',
200
+ assetModuleFilename: 'static/media/[name][ext]',
158
201
  // webpack uses `publicPath` to determine where the app is being served from.
159
202
  // It requires a trailing slash, or the file assets will get an incorrect path.
160
203
  // We inferred the "public path" (such as / or /my-project) from homepage.
@@ -167,9 +210,22 @@ module.exports = function (webpackEnv) {
167
210
  .replace(/\\/g, '/')
168
211
  : isEnvDevelopment &&
169
212
  (info => path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')),
170
- // this defaults to 'window', but by setting it to 'this' then
171
- // module chunks which are built will work in web workers as well.
172
- globalObject: 'this',
213
+ },
214
+ cache: {
215
+ type: 'filesystem',
216
+ version: createEnvironmentHash(env.raw),
217
+ cacheDirectory: paths.appWebpackCache,
218
+ store: 'pack',
219
+ buildDependencies: {
220
+ defaultWebpack: ['webpack/lib/'],
221
+ config: [__filename],
222
+ tsconfig: [paths.appTsConfig, paths.appJsConfig].filter(f =>
223
+ fs.existsSync(f)
224
+ ),
225
+ },
226
+ },
227
+ infrastructureLogging: {
228
+ level: 'none',
173
229
  },
174
230
  optimization: {
175
231
  minimize: false,
@@ -246,12 +302,12 @@ module.exports = function (webpackEnv) {
246
302
  'react-dom$': 'react-dom/profiling',
247
303
  'scheduler/tracing': 'scheduler/tracing-profiling',
248
304
  }),
305
+ // Allows replacing react-dom with @reactunity/renderer to support some functionality like `unstable_batchedUpdates`
306
+ 'react-dom': '@reactunity/renderer',
307
+
249
308
  ...(modules.webpackAliases || {}),
250
309
  },
251
310
  plugins: [
252
- // Adds support for installing with Plug'n'Play, leading to faster installs and adding
253
- // guards against forgotten dependencies and such.
254
- PnpWebpackPlugin,
255
311
  // Prevents users from importing files from outside of src/ (or node_modules/).
256
312
  // This often causes confusion because we only process files within src/ with babel.
257
313
  // To fix this, we prevent you from importing files out of src/ -- if you'd like to,
@@ -259,20 +315,24 @@ module.exports = function (webpackEnv) {
259
315
  // Make sure your source files are compiled, as they will not be processed in any way.
260
316
  new ModuleScopePlugin(paths.appSrc, [
261
317
  paths.appPackageJson,
262
- reactRefreshOverlayEntry,
318
+ reactRefreshRuntimeEntry,
319
+ reactRefreshWebpackPluginRuntimeEntry,
320
+ babelRuntimeEntry,
321
+ babelRuntimeEntryHelpers,
322
+ babelRuntimeRegenerator,
263
323
  ]),
264
324
  ],
265
325
  },
266
- resolveLoader: {
267
- plugins: [
268
- // Also related to Plug'n'Play, but this time it tells webpack to load its loaders
269
- // from the current package.
270
- PnpWebpackPlugin.moduleLoader(module),
271
- ],
272
- },
273
326
  module: {
274
327
  strictExportPresence: true,
275
328
  rules: [
329
+ // Handle node_modules packages that contain sourcemaps
330
+ shouldUseSourceMap && {
331
+ enforce: 'pre',
332
+ exclude: /@babel(?:\/|\\{1,2})runtime/,
333
+ test: /\.(js|mjs|jsx|ts|tsx|css)$/,
334
+ loader: require.resolve('source-map-loader'),
335
+ },
276
336
  {
277
337
  // "oneOf" will traverse all following loaders until one will
278
338
  // match the requirements. When no loader matches it will fall
@@ -283,10 +343,11 @@ module.exports = function (webpackEnv) {
283
343
  // A missing `test` is equivalent to a match.
284
344
  {
285
345
  test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
286
- loader: require.resolve('url-loader'),
287
- options: {
288
- limit: imageInlineSizeLimit,
289
- name: 'static/media/[name].[ext]',
346
+ type: 'asset',
347
+ parser: {
348
+ dataUrlCondition: {
349
+ maxSize: imageInlineSizeLimit,
350
+ },
290
351
  },
291
352
  },
292
353
  // Process application JS with Babel.
@@ -304,7 +365,6 @@ module.exports = function (webpackEnv) {
304
365
  require.resolve('babel-preset-react-app'),
305
366
  {
306
367
  runtime: modules.hasJsxRuntime ? 'automatic' : 'classic',
307
- absoluteRuntime: false,
308
368
  },
309
369
  ],
310
370
  ],
@@ -329,10 +389,6 @@ module.exports = function (webpackEnv) {
329
389
  ),
330
390
  // @remove-on-eject-end
331
391
  plugins: [
332
- [
333
- require.resolve('babel-plugin-named-asset-import'),
334
- { loaderMap: {} },
335
- ],
336
392
  isEnvDevelopment &&
337
393
  shouldUseReactRefresh &&
338
394
  require.resolve('react-refresh/babel'),
@@ -400,6 +456,9 @@ module.exports = function (webpackEnv) {
400
456
  sourceMap: isEnvProduction
401
457
  ? shouldUseSourceMap
402
458
  : isEnvDevelopment,
459
+ modules: {
460
+ mode: 'icss',
461
+ },
403
462
  }),
404
463
  // Don't consider CSS imports dead code even if the
405
464
  // containing package claims to have no side effects.
@@ -417,6 +476,7 @@ module.exports = function (webpackEnv) {
417
476
  ? shouldUseSourceMap
418
477
  : isEnvDevelopment,
419
478
  modules: {
479
+ mode: 'local',
420
480
  getLocalIdent: getCSSModuleLocalIdent,
421
481
  },
422
482
  }),
@@ -433,6 +493,9 @@ module.exports = function (webpackEnv) {
433
493
  sourceMap: isEnvProduction
434
494
  ? shouldUseSourceMap
435
495
  : isEnvDevelopment,
496
+ modules: {
497
+ mode: 'icss',
498
+ },
436
499
  },
437
500
  'sass-loader'
438
501
  ),
@@ -453,6 +516,7 @@ module.exports = function (webpackEnv) {
453
516
  ? shouldUseSourceMap
454
517
  : isEnvDevelopment,
455
518
  modules: {
519
+ mode: 'local',
456
520
  getLocalIdent: getCSSModuleLocalIdent,
457
521
  },
458
522
  },
@@ -464,35 +528,24 @@ module.exports = function (webpackEnv) {
464
528
  test: /\.txt$/i,
465
529
  use: 'raw-loader',
466
530
  },
467
- // svgr loader is disabled and SVGs are converted to PNG in React Unity
468
- {
469
- test: /\.svg$/i,
470
- loader: 'svg-to-png-loader',
471
- options: {
472
- name: 'static/svg/[name]-[height]x[width].png',
473
- },
474
- },
475
531
  // "file" loader makes sure those assets get served by WebpackDevServer.
476
532
  // When you `import` an asset, you get its (virtual) filename.
477
533
  // In production, they would get copied to the `build` folder.
478
534
  // This loader doesn't use a "test" so it will catch all modules
479
535
  // that fall through the other loaders.
480
536
  {
481
- loader: require.resolve('file-loader'),
482
537
  // Exclude `js` files to keep "css" loader working as it injects
483
538
  // its runtime that would otherwise be processed through "file" loader.
484
539
  // Also exclude `json` extensions so they get processed
485
540
  // by webpacks internal loaders.
486
- exclude: [/\.(js|mjs|jsx|ts|tsx)$/, /\.json$/],
487
- options: {
488
- name: 'static/media/[name].[ext]',
489
- },
541
+ exclude: [/^$/, /\.(js|mjs|jsx|ts|tsx)$/, /\.json$/],
542
+ type: 'asset/resource',
490
543
  },
491
544
  // ** STOP ** Are you adding a new loader?
492
545
  // Make sure to add the new loader(s) before the "file" loader.
493
546
  ],
494
547
  },
495
- ],
548
+ ].filter(Boolean),
496
549
  },
497
550
  plugins: [
498
551
  // This gives some necessary context to module not found errors, such as
@@ -505,31 +558,48 @@ module.exports = function (webpackEnv) {
505
558
  // Otherwise React will be compiled in the very slow development mode.
506
559
  new webpack.DefinePlugin(env.stringified),
507
560
  // Experimental hot reloading for React .
508
- // https://github.com/facebook/react/tree/master/packages/react-refresh
561
+ // https://github.com/facebook/react/tree/main/packages/react-refresh
509
562
  isEnvDevelopment &&
510
563
  shouldUseReactRefresh &&
511
564
  new ReactRefreshWebpackPlugin({
512
- overlay: {
513
- entry: webpackDevClientEntry,
514
- // The expected exports are slightly different from what the overlay exports,
515
- // so an interop is included here to enable feedback on module-level errors.
516
- module: reactRefreshOverlayEntry,
517
- // Since we ship a custom dev client and overlay integration,
518
- // the bundled socket handling logic can be eliminated.
519
- sockIntegration: false,
520
- },
565
+ overlay: false,
521
566
  }),
522
567
  // Watcher doesn't work well if you mistype casing in a path so we use
523
568
  // a plugin that prints an error when you attempt to do this.
524
569
  // See https://github.com/facebook/create-react-app/issues/240
525
570
  isEnvDevelopment && new CaseSensitivePathsPlugin(),
526
- // If you require a missing module and then `npm install` it, you still have
527
- // to restart the development server for webpack to discover it. This plugin
528
- // makes the discovery automatic so you don't have to restart.
529
- // See https://github.com/facebook/create-react-app/issues/186
530
- isEnvDevelopment &&
531
- new WatchMissingNodeModulesPlugin(paths.appNodeModules),
571
+ shouldExtractCss &&
572
+ new MiniCssExtractPlugin({
573
+ // Options similar to the same options in webpackOptions.output
574
+ // both options are optional
575
+ filename: 'static/css/[name].css',
576
+ chunkFilename: 'static/css/[name].chunk.css',
577
+ }),
578
+ // Generate an asset manifest file with the following content:
579
+ // - "files" key: Mapping of all asset filenames to their corresponding
580
+ // output file so that tools can pick it up without having to parse
581
+ // `index.html`
582
+ // - "entrypoints" key: Array of files which are included in `index.html`,
583
+ // can be used to reconstruct the HTML if necessary
584
+ generateManifest &&
585
+ new WebpackManifestPlugin({
586
+ fileName: 'asset-manifest.json',
587
+ publicPath: paths.publicUrlOrPath,
588
+ generate: (seed, files, entrypoints) => {
589
+ const manifestFiles = files.reduce((manifest, file) => {
590
+ manifest[file.name] = file.path;
591
+ return manifest;
592
+ }, seed);
593
+ const entrypointFiles = entrypoints.main.filter(
594
+ fileName => !fileName.endsWith('.map')
595
+ );
532
596
 
597
+ return {
598
+ files: manifestFiles,
599
+ entrypoints: entrypointFiles,
600
+ };
601
+ },
602
+ }),
533
603
  // Moment.js is an extremely popular library that bundles large locale files
534
604
  // by default due to how webpack interprets its code. This is a practical
535
605
  // solution that requires the user to opt into importing specific locales.
@@ -543,36 +613,54 @@ module.exports = function (webpackEnv) {
543
613
  // TypeScript type checking
544
614
  useTypeScript &&
545
615
  new ForkTsCheckerWebpackPlugin({
546
- typescript: resolve.sync('typescript', {
547
- basedir: paths.appNodeModules,
548
- }),
549
616
  async: isEnvDevelopment,
550
- checkSyntacticErrors: true,
551
- resolveModuleNameModule: process.versions.pnp
552
- ? `${__dirname}/pnpTs.js`
553
- : undefined,
554
- resolveTypeReferenceDirectiveModule: process.versions.pnp
555
- ? `${__dirname}/pnpTs.js`
556
- : undefined,
557
- tsconfig: paths.appTsConfig,
558
- reportFiles: [
617
+ typescript: {
618
+ typescriptPath: resolve.sync('typescript', {
619
+ basedir: paths.appNodeModules,
620
+ }),
621
+ configOverwrite: {
622
+ compilerOptions: {
623
+ sourceMap: isEnvProduction
624
+ ? shouldUseSourceMap
625
+ : isEnvDevelopment,
626
+ skipLibCheck: true,
627
+ inlineSourceMap: false,
628
+ declarationMap: false,
629
+ noEmit: true,
630
+ incremental: true,
631
+ tsBuildInfoFile: paths.appTsBuildInfoFile,
632
+ },
633
+ },
634
+ context: paths.appPath,
635
+ diagnosticOptions: {
636
+ syntactic: true,
637
+ },
638
+ mode: 'write-references',
639
+ // profile: true,
640
+ },
641
+ issue: {
559
642
  // This one is specifically to match during CI tests,
560
643
  // as micromatch doesn't match
561
644
  // '../cra-template-typescript/template/src/App.tsx'
562
645
  // otherwise.
563
- '../**/src/**/*.{ts,tsx}',
564
- '**/src/**/*.{ts,tsx}',
565
- '!**/src/**/__tests__/**',
566
- '!**/src/**/?(*.)(spec|test).*',
567
- '!**/src/setupProxy.*',
568
- '!**/src/setupTests.*',
569
- ],
570
- silent: true,
571
- // The formatter is invoked directly in WebpackDevServerUtils during development
572
- formatter: isEnvProduction ? typescriptFormatter : undefined,
646
+ include: [
647
+ { file: '../**/src/**/*.{ts,tsx}' },
648
+ { file: '**/src/**/*.{ts,tsx}' },
649
+ ],
650
+ exclude: [
651
+ { file: '**/src/**/__tests__/**' },
652
+ { file: '**/src/**/?(*.){spec|test}.*' },
653
+ { file: '**/src/setupProxy.*' },
654
+ { file: '**/src/setupTests.*' },
655
+ ],
656
+ },
657
+ logger: {
658
+ infrastructure: 'silent',
659
+ },
573
660
  }),
574
661
  !disableESLintPlugin &&
575
662
  new ESLintPlugin({
663
+ // Plugin options
576
664
  formatter: require.resolve('react-dev-utils/eslintFormatter'),
577
665
  eslintPath: require.resolve('eslint'),
578
666
  failOnError: !(isEnvDevelopment && emitErrorsAsWarnings),
@@ -585,3 +673,21 @@ module.exports = function (webpackEnv) {
585
673
  performance: false,
586
674
  };
587
675
  };
676
+
677
+ module.exports = function (webpackEnv) {
678
+ const baseConfig = baseConfigFactory(webpackEnv);
679
+
680
+ if (fs.existsSync(paths.webpackSetup)) {
681
+ const customSetup = require(paths.webpackSetup);
682
+
683
+ console.log(`Using custom webpack config found in '${paths.webpackSetup}'`);
684
+
685
+ if (typeof customSetup !== 'function') {
686
+ throw new Error('Custom webpack config file must export a function that accepts `env` as first parameter and `defaultConfig` as second');
687
+ }
688
+
689
+ return customSetup(webpackEnv, baseConfig);
690
+ }
691
+
692
+ return baseConfig;
693
+ };