@reactunity/scripts 0.19.2 → 0.20.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.
- package/bin/react-unity-scripts.js +11 -31
- package/config/babel-preset-extended.js +3 -3
- package/config/env.js +10 -20
- package/config/getHttpsConfig.js +7 -23
- package/config/jest/babelTransform.js +1 -9
- package/config/jest/cssTransform.js +1 -9
- package/config/jest/fileTransform.js +2 -2
- package/config/modules.js +11 -17
- package/config/paths.js +10 -37
- package/config/unityMiddleware.js +2 -2
- package/config/webpack/persistentCache/createEnvironmentHash.js +3 -3
- package/config/webpack.config.js +132 -211
- package/config/webpackDevServer.config.js +7 -16
- package/lib/types/base.d.ts +1 -3
- package/package.json +32 -42
- package/scripts/build.js +19 -63
- package/scripts/clean.js +2 -3
- package/scripts/eject.js +40 -109
- package/scripts/init.js +33 -102
- package/scripts/start.js +18 -43
- package/scripts/test.js +9 -29
- package/scripts/utils/cleanBuildDirectory.js +14 -15
- package/scripts/utils/createJestConfig.js +16 -61
- package/scripts/utils/verifyTypeScriptSetup.js +49 -100
- package/tsconfig.json +1 -3
- package/config/eslint/base.js +0 -43
- package/config/eslint/config.js +0 -252
- package/config/eslint/jest.js +0 -59
- package/config/eslintConfig.js +0 -31
- package/scripts/lint.js +0 -46
package/config/webpack.config.js
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* Copyright (c) 2015-present, Facebook, Inc.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
*/
|
|
8
|
-
// @remove-on-eject-end
|
|
9
|
-
'use strict';
|
|
10
|
-
|
|
11
|
-
const fs = require('fs');
|
|
12
|
-
const path = require('path');
|
|
1
|
+
const fs = require('node:fs');
|
|
2
|
+
const path = require('node:path');
|
|
13
3
|
const webpack = require('webpack');
|
|
14
4
|
const resolve = require('resolve');
|
|
15
5
|
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
|
|
@@ -18,8 +8,6 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
|
18
8
|
const { WebpackManifestPlugin } = require('webpack-manifest-plugin');
|
|
19
9
|
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
|
|
20
10
|
const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent');
|
|
21
|
-
const ESLintPlugin = require('eslint-webpack-plugin');
|
|
22
|
-
const eslintConfig = require('./eslintConfig');
|
|
23
11
|
const paths = require('./paths');
|
|
24
12
|
const modules = require('./modules');
|
|
25
13
|
const getClientEnvironment = require('./env');
|
|
@@ -41,47 +29,36 @@ const shouldUseSourceMap = sourceMapVar !== 'false' && !!sourceMapVar;
|
|
|
41
29
|
const sourceMapType = sourceMapVar !== 'false' && sourceMapVar !== 'true' && sourceMapVar;
|
|
42
30
|
|
|
43
31
|
const reactRefreshRuntimeEntry = require.resolve('react-refresh/runtime');
|
|
44
|
-
const reactRefreshWebpackPluginRuntimeEntry = require.resolve(
|
|
45
|
-
'@pmmmwh/react-refresh-webpack-plugin'
|
|
46
|
-
);
|
|
32
|
+
const reactRefreshWebpackPluginRuntimeEntry = require.resolve('@pmmmwh/react-refresh-webpack-plugin');
|
|
47
33
|
const babelRuntimeEntry = require.resolve('babel-preset-react-app');
|
|
48
|
-
const babelRuntimeEntryHelpers = require.resolve(
|
|
49
|
-
'@babel/runtime/helpers/esm/assertThisInitialized',
|
|
50
|
-
{ paths: [babelRuntimeEntry] }
|
|
51
|
-
);
|
|
34
|
+
const babelRuntimeEntryHelpers = require.resolve('@babel/runtime/helpers/esm/assertThisInitialized', { paths: [babelRuntimeEntry] });
|
|
52
35
|
const babelRuntimeRegenerator = require.resolve('@babel/runtime/regenerator', {
|
|
53
36
|
paths: [babelRuntimeEntry],
|
|
54
37
|
});
|
|
55
38
|
|
|
56
|
-
const emitErrorsAsWarnings = process.env.ESLINT_NO_DEV_ERRORS === 'true';
|
|
57
|
-
const disableESLintPlugin = process.env.DISABLE_ESLINT_PLUGIN === 'true';
|
|
58
39
|
const extractCss = process.env.EXTRACT_CSS === 'true';
|
|
59
40
|
const generateManifest = process.env.GENERATE_MANIFEST !== 'false';
|
|
60
41
|
const enableScope = process.env.ENABLE_SCOPE === 'true';
|
|
61
42
|
|
|
62
|
-
const imageInlineSizeLimit = parseInt(
|
|
63
|
-
process.env.IMAGE_INLINE_SIZE_LIMIT || '0'
|
|
64
|
-
);
|
|
43
|
+
const imageInlineSizeLimit = Number.parseInt(process.env.IMAGE_INLINE_SIZE_LIMIT || '0');
|
|
65
44
|
|
|
66
45
|
// Check if TypeScript is setup
|
|
67
46
|
const useTypeScript = fs.existsSync(paths.appTsConfig);
|
|
68
47
|
|
|
69
48
|
// Check if Tailwind config exists
|
|
70
|
-
const useTailwind = fs.existsSync(
|
|
71
|
-
path.join(paths.appPath, 'tailwind.config.js')
|
|
72
|
-
);
|
|
49
|
+
const useTailwind = fs.existsSync(path.join(paths.appPath, 'tailwind.config.js'));
|
|
73
50
|
|
|
74
51
|
const warnedAboutPlugin = {};
|
|
75
52
|
const usePostcssPluginIfExists = (name, options = {}) => {
|
|
76
53
|
try {
|
|
77
54
|
if (require.resolve(name)) {
|
|
78
55
|
if (!warnedAboutPlugin[name]) {
|
|
79
|
-
console.log(
|
|
56
|
+
console.log(`Using plugin ${name}`);
|
|
80
57
|
warnedAboutPlugin[name] = true;
|
|
81
58
|
}
|
|
82
59
|
return { [name]: options };
|
|
83
60
|
}
|
|
84
|
-
} catch (err) {
|
|
61
|
+
} catch (err) {}
|
|
85
62
|
return {};
|
|
86
63
|
};
|
|
87
64
|
|
|
@@ -91,30 +68,29 @@ const cssModuleRegex = /\.module\.css$/;
|
|
|
91
68
|
const sassRegex = /\.(scss|sass)$/;
|
|
92
69
|
const sassModuleRegex = /\.module\.(scss|sass)$/;
|
|
93
70
|
|
|
94
|
-
|
|
95
71
|
// Treat files under `src/entry` as separate entry points
|
|
96
72
|
const appDirectory = fs.realpathSync(process.cwd());
|
|
97
73
|
const entryDirectory = path.join(appDirectory, 'src/entry');
|
|
98
|
-
const entries = !fs.existsSync(entryDirectory)
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
74
|
+
const entries = !fs.existsSync(entryDirectory)
|
|
75
|
+
? []
|
|
76
|
+
: fs
|
|
77
|
+
.readdirSync(entryDirectory, { withFileTypes: true })
|
|
78
|
+
.filter((x) => x.isFile())
|
|
79
|
+
.filter((x) => /\.(js|mjs|jsx|ts|tsx)$/.test(x.name))
|
|
80
|
+
.map((x) => path.resolve(entryDirectory, x.name));
|
|
103
81
|
const entryObj = {};
|
|
104
82
|
for (const entry of entries) entryObj[path.basename(entry, path.extname(entry))] = entry;
|
|
105
83
|
|
|
106
|
-
|
|
107
84
|
// This is the production and development configuration.
|
|
108
85
|
// It is focused on developer experience, fast rebuilds, and a minimal bundle.
|
|
109
|
-
const baseConfigFactory =
|
|
86
|
+
const baseConfigFactory = (webpackEnv) => {
|
|
110
87
|
const isEnvDevelopment = webpackEnv === 'development';
|
|
111
88
|
const isEnvProduction = webpackEnv === 'production';
|
|
112
89
|
const shouldExtractCss = isEnvProduction && extractCss;
|
|
113
90
|
|
|
114
91
|
// Variable used for enabling profiling in Production
|
|
115
92
|
// passed into alias object. Uses a flag if passed into the build command
|
|
116
|
-
const isEnvProductionProfile =
|
|
117
|
-
isEnvProduction && process.argv.includes('--profile');
|
|
93
|
+
const isEnvProductionProfile = isEnvProduction && process.argv.includes('--profile');
|
|
118
94
|
|
|
119
95
|
// We will provide `paths.publicUrlOrPath` to our app
|
|
120
96
|
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
|
|
@@ -127,15 +103,14 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
127
103
|
// common function to get style loaders
|
|
128
104
|
const getStyleLoaders = (cssOptions, preProcessor) => {
|
|
129
105
|
const loaders = [
|
|
130
|
-
!shouldExtractCss
|
|
106
|
+
!shouldExtractCss
|
|
107
|
+
? require.resolve('style-loader')
|
|
131
108
|
: {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
: {},
|
|
138
|
-
},
|
|
109
|
+
loader: MiniCssExtractPlugin.loader,
|
|
110
|
+
// css is located in `static/css`, use '../../' to locate index.html folder
|
|
111
|
+
// in production `paths.publicUrlOrPath` can be a relative path
|
|
112
|
+
options: paths.publicUrlOrPath.startsWith('.') ? { publicPath: '../../' } : {},
|
|
113
|
+
},
|
|
139
114
|
{
|
|
140
115
|
loader: require.resolve('css-loader'),
|
|
141
116
|
options: cssOptions,
|
|
@@ -153,7 +128,7 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
153
128
|
config: false,
|
|
154
129
|
plugins: {
|
|
155
130
|
...usePostcssPluginIfExists('postcss-import'),
|
|
156
|
-
|
|
131
|
+
tailwindcss: {},
|
|
157
132
|
...usePostcssPluginIfExists('postcss-nesting'),
|
|
158
133
|
...usePostcssPluginIfExists('postcss-custom-properties'),
|
|
159
134
|
...usePostcssPluginIfExists('postcss-css-variables'),
|
|
@@ -179,7 +154,7 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
179
154
|
sourceMap: true,
|
|
180
155
|
warnRuleAsWarning: false,
|
|
181
156
|
},
|
|
182
|
-
}
|
|
157
|
+
},
|
|
183
158
|
);
|
|
184
159
|
}
|
|
185
160
|
return loaders;
|
|
@@ -192,9 +167,9 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
192
167
|
// Stop compilation early in production
|
|
193
168
|
bail: isEnvProduction,
|
|
194
169
|
devtool: isEnvProduction
|
|
195
|
-
?
|
|
196
|
-
?
|
|
197
|
-
: false
|
|
170
|
+
? shouldUseSourceMap
|
|
171
|
+
? sourceMapType || 'source-map'
|
|
172
|
+
: false
|
|
198
173
|
: isEnvDevelopment && (sourceMapType || 'cheap-module-source-map'),
|
|
199
174
|
// These are the "entry points" to our application.
|
|
200
175
|
// This means they will be the "root" imports that are included in JS bundle.
|
|
@@ -212,9 +187,7 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
212
187
|
// In development, it does not produce real files.
|
|
213
188
|
filename: isEnvDevelopment ? '[name].js' : process.env.FILENAME || '[name].js',
|
|
214
189
|
// There are also additional JS chunk files if you use code splitting.
|
|
215
|
-
chunkFilename: isEnvProduction
|
|
216
|
-
? 'static/js/[name].chunk.js'
|
|
217
|
-
: isEnvDevelopment && 'static/js/[name].chunk.js',
|
|
190
|
+
chunkFilename: isEnvProduction ? 'static/js/[name].chunk.js' : isEnvDevelopment && 'static/js/[name].chunk.js',
|
|
218
191
|
assetModuleFilename: 'static/media/[name][ext][ext]',
|
|
219
192
|
// webpack uses `publicPath` to determine where the app is being served from.
|
|
220
193
|
// It requires a trailing slash, or the file assets will get an incorrect path.
|
|
@@ -222,12 +195,8 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
222
195
|
publicPath: paths.publicUrlOrPath,
|
|
223
196
|
// Point sourcemap entries to original disk location (format as URL on Windows)
|
|
224
197
|
devtoolModuleFilenameTemplate: isEnvProduction
|
|
225
|
-
? info =>
|
|
226
|
-
|
|
227
|
-
.relative(paths.appSrc, info.absoluteResourcePath)
|
|
228
|
-
.replace(/\\/g, '/')
|
|
229
|
-
: isEnvDevelopment &&
|
|
230
|
-
(info => path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')),
|
|
198
|
+
? (info) => path.relative(paths.appSrc, info.absoluteResourcePath).replace(/\\/g, '/')
|
|
199
|
+
: isEnvDevelopment && ((info) => path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')),
|
|
231
200
|
},
|
|
232
201
|
cache: {
|
|
233
202
|
type: 'filesystem',
|
|
@@ -237,9 +206,7 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
237
206
|
buildDependencies: {
|
|
238
207
|
defaultWebpack: ['webpack/lib/'],
|
|
239
208
|
config: [__filename],
|
|
240
|
-
tsconfig: [paths.appTsConfig, paths.appJsConfig].filter(f =>
|
|
241
|
-
fs.existsSync(f)
|
|
242
|
-
),
|
|
209
|
+
tsconfig: [paths.appTsConfig, paths.appJsConfig].filter((f) => fs.existsSync(f)),
|
|
243
210
|
},
|
|
244
211
|
},
|
|
245
212
|
infrastructureLogging: {
|
|
@@ -298,18 +265,14 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
298
265
|
// We placed these paths second because we want `node_modules` to "win"
|
|
299
266
|
// if there are any conflicts. This matches Node resolution mechanism.
|
|
300
267
|
// https://github.com/facebook/create-react-app/issues/253
|
|
301
|
-
modules: ['node_modules', paths.appNodeModules].concat(
|
|
302
|
-
modules.additionalModulePaths || []
|
|
303
|
-
),
|
|
268
|
+
modules: ['node_modules', paths.appNodeModules].concat(modules.additionalModulePaths || []),
|
|
304
269
|
// These are the reasonable defaults supported by the Node ecosystem.
|
|
305
270
|
// We also include JSX as a common component filename extension to support
|
|
306
271
|
// some tools, although we do not recommend using it, see:
|
|
307
272
|
// https://github.com/facebook/create-react-app/issues/290
|
|
308
273
|
// `web` extension prefixes have been added for better support
|
|
309
274
|
// for React Native Web.
|
|
310
|
-
extensions: paths.moduleFileExtensions
|
|
311
|
-
.map(ext => `.${ext}`)
|
|
312
|
-
.filter(ext => useTypeScript || !ext.includes('ts')),
|
|
275
|
+
extensions: paths.moduleFileExtensions.map((ext) => `.${ext}`).filter((ext) => useTypeScript || !ext.includes('ts')),
|
|
313
276
|
alias: {
|
|
314
277
|
// Support React Native Web
|
|
315
278
|
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
|
|
@@ -336,14 +299,15 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
336
299
|
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
|
|
337
300
|
// please link the files into your node_modules/ and let module-resolution kick in.
|
|
338
301
|
// Make sure your source files are compiled, as they will not be processed in any way.
|
|
339
|
-
enableScope &&
|
|
340
|
-
paths.
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
302
|
+
enableScope &&
|
|
303
|
+
new ModuleScopePlugin(paths.appSrc, [
|
|
304
|
+
paths.appPackageJson,
|
|
305
|
+
reactRefreshRuntimeEntry,
|
|
306
|
+
reactRefreshWebpackPluginRuntimeEntry,
|
|
307
|
+
babelRuntimeEntry,
|
|
308
|
+
babelRuntimeEntryHelpers,
|
|
309
|
+
babelRuntimeRegenerator,
|
|
310
|
+
]),
|
|
347
311
|
].filter(Boolean),
|
|
348
312
|
},
|
|
349
313
|
module: {
|
|
@@ -407,9 +371,7 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
407
371
|
include: paths.appPath,
|
|
408
372
|
loader: require.resolve('babel-loader'),
|
|
409
373
|
options: {
|
|
410
|
-
customize: require.resolve(
|
|
411
|
-
'babel-preset-react-app/webpack-overrides'
|
|
412
|
-
),
|
|
374
|
+
customize: require.resolve('babel-preset-react-app/webpack-overrides'),
|
|
413
375
|
presets: [
|
|
414
376
|
[
|
|
415
377
|
require.resolve('./babel-preset-extended'),
|
|
@@ -428,23 +390,14 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
428
390
|
// We remove this when the user ejects because the default
|
|
429
391
|
// is sane and uses Babel options. Instead of options, we use
|
|
430
392
|
// the react-unity-scripts and babel-preset-react-app versions.
|
|
431
|
-
cacheIdentifier: getCacheIdentifier(
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
'babel-preset-react-app',
|
|
438
|
-
'react-dev-utils',
|
|
439
|
-
'react-unity-scripts',
|
|
440
|
-
]
|
|
441
|
-
),
|
|
393
|
+
cacheIdentifier: getCacheIdentifier(isEnvProduction ? 'production' : isEnvDevelopment && 'development', [
|
|
394
|
+
'babel-plugin-named-asset-import',
|
|
395
|
+
'babel-preset-react-app',
|
|
396
|
+
'react-dev-utils',
|
|
397
|
+
'react-unity-scripts',
|
|
398
|
+
]),
|
|
442
399
|
// @remove-on-eject-end
|
|
443
|
-
plugins: [
|
|
444
|
-
isEnvDevelopment &&
|
|
445
|
-
shouldUseReactRefresh &&
|
|
446
|
-
require.resolve('react-refresh/babel'),
|
|
447
|
-
].filter(Boolean),
|
|
400
|
+
plugins: [isEnvDevelopment && shouldUseReactRefresh && require.resolve('react-refresh/babel')].filter(Boolean),
|
|
448
401
|
// This is a feature of `babel-loader` for webpack (not Babel itself).
|
|
449
402
|
// It enables caching results in ./node_modules/.cache/babel-loader/
|
|
450
403
|
// directory for faster rebuilds.
|
|
@@ -464,27 +417,17 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
464
417
|
babelrc: true,
|
|
465
418
|
configFile: true,
|
|
466
419
|
compact: false,
|
|
467
|
-
presets: [
|
|
468
|
-
[
|
|
469
|
-
require.resolve('babel-preset-react-app/dependencies'),
|
|
470
|
-
{ helpers: true },
|
|
471
|
-
],
|
|
472
|
-
],
|
|
420
|
+
presets: [[require.resolve('babel-preset-react-app/dependencies'), { helpers: true }]],
|
|
473
421
|
cacheDirectory: true,
|
|
474
422
|
// See #6846 for context on why cacheCompression is disabled
|
|
475
423
|
cacheCompression: false,
|
|
476
424
|
// @remove-on-eject-begin
|
|
477
|
-
cacheIdentifier: getCacheIdentifier(
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
'babel-preset-react-app',
|
|
484
|
-
'react-dev-utils',
|
|
485
|
-
'react-unity-scripts',
|
|
486
|
-
]
|
|
487
|
-
),
|
|
425
|
+
cacheIdentifier: getCacheIdentifier(isEnvProduction ? 'production' : isEnvDevelopment && 'development', [
|
|
426
|
+
'babel-plugin-named-asset-import',
|
|
427
|
+
'babel-preset-react-app',
|
|
428
|
+
'react-dev-utils',
|
|
429
|
+
'react-unity-scripts',
|
|
430
|
+
]),
|
|
488
431
|
// @remove-on-eject-end
|
|
489
432
|
// Babel sourcemaps are needed for debugging into node_modules
|
|
490
433
|
// code. Without the options below, debuggers like VSCode
|
|
@@ -505,9 +448,7 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
505
448
|
exclude: cssModuleRegex,
|
|
506
449
|
use: getStyleLoaders({
|
|
507
450
|
importLoaders: 1,
|
|
508
|
-
sourceMap: isEnvProduction
|
|
509
|
-
? shouldUseSourceMap
|
|
510
|
-
: isEnvDevelopment,
|
|
451
|
+
sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
|
|
511
452
|
modules: {
|
|
512
453
|
mode: 'icss',
|
|
513
454
|
},
|
|
@@ -524,9 +465,7 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
524
465
|
test: cssModuleRegex,
|
|
525
466
|
use: getStyleLoaders({
|
|
526
467
|
importLoaders: 1,
|
|
527
|
-
sourceMap: isEnvProduction
|
|
528
|
-
? shouldUseSourceMap
|
|
529
|
-
: isEnvDevelopment,
|
|
468
|
+
sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
|
|
530
469
|
modules: {
|
|
531
470
|
mode: 'local',
|
|
532
471
|
namedExport: false,
|
|
@@ -544,14 +483,12 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
544
483
|
use: getStyleLoaders(
|
|
545
484
|
{
|
|
546
485
|
importLoaders: 3,
|
|
547
|
-
sourceMap: isEnvProduction
|
|
548
|
-
? shouldUseSourceMap
|
|
549
|
-
: isEnvDevelopment,
|
|
486
|
+
sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
|
|
550
487
|
modules: {
|
|
551
488
|
mode: 'icss',
|
|
552
489
|
},
|
|
553
490
|
},
|
|
554
|
-
'sass-loader'
|
|
491
|
+
'sass-loader',
|
|
555
492
|
),
|
|
556
493
|
// Don't consider CSS imports dead code even if the
|
|
557
494
|
// containing package claims to have no side effects.
|
|
@@ -566,9 +503,7 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
566
503
|
use: getStyleLoaders(
|
|
567
504
|
{
|
|
568
505
|
importLoaders: 3,
|
|
569
|
-
sourceMap: isEnvProduction
|
|
570
|
-
? shouldUseSourceMap
|
|
571
|
-
: isEnvDevelopment,
|
|
506
|
+
sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
|
|
572
507
|
modules: {
|
|
573
508
|
mode: 'local',
|
|
574
509
|
namedExport: false,
|
|
@@ -576,7 +511,7 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
576
511
|
getLocalIdent: getCSSModuleLocalIdent,
|
|
577
512
|
},
|
|
578
513
|
},
|
|
579
|
-
'sass-loader'
|
|
514
|
+
'sass-loader',
|
|
580
515
|
),
|
|
581
516
|
},
|
|
582
517
|
// raw-loader is added by React Unity for its usefulness and for the sake of completion
|
|
@@ -616,21 +551,21 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
616
551
|
// Experimental hot reloading for React .
|
|
617
552
|
// https://github.com/facebook/react/tree/main/packages/react-refresh
|
|
618
553
|
isEnvDevelopment &&
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
554
|
+
shouldUseReactRefresh &&
|
|
555
|
+
new ReactRefreshWebpackPlugin({
|
|
556
|
+
overlay: false,
|
|
557
|
+
}),
|
|
623
558
|
// Watcher doesn't work well if you mistype casing in a path so we use
|
|
624
559
|
// a plugin that prints an error when you attempt to do this.
|
|
625
560
|
// See https://github.com/facebook/create-react-app/issues/240
|
|
626
561
|
isEnvDevelopment && new CaseSensitivePathsPlugin(),
|
|
627
562
|
shouldExtractCss &&
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
563
|
+
new MiniCssExtractPlugin({
|
|
564
|
+
// Options similar to the same options in webpackOptions.output
|
|
565
|
+
// both options are optional
|
|
566
|
+
filename: 'static/css/[name].css',
|
|
567
|
+
chunkFilename: 'static/css/[name].chunk.css',
|
|
568
|
+
}),
|
|
634
569
|
// Generate an asset manifest file with the following content:
|
|
635
570
|
// - "files" key: Mapping of all asset filenames to their corresponding
|
|
636
571
|
// output file so that tools can pick it up without having to parse
|
|
@@ -638,24 +573,22 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
638
573
|
// - "entrypoints" key: Array of files which are included in `index.html`,
|
|
639
574
|
// can be used to reconstruct the HTML if necessary
|
|
640
575
|
generateManifest &&
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
fileName => !fileName.endsWith('.map')
|
|
651
|
-
);
|
|
576
|
+
new WebpackManifestPlugin({
|
|
577
|
+
fileName: 'asset-manifest.json',
|
|
578
|
+
publicPath: paths.publicUrlOrPath,
|
|
579
|
+
generate: (seed, files, entrypoints) => {
|
|
580
|
+
const manifestFiles = files.reduce((manifest, file) => {
|
|
581
|
+
manifest[file.name] = file.path;
|
|
582
|
+
return manifest;
|
|
583
|
+
}, seed);
|
|
584
|
+
const entrypointFiles = entrypoints.index.filter((fileName) => !fileName.endsWith('.map'));
|
|
652
585
|
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
586
|
+
return {
|
|
587
|
+
files: manifestFiles,
|
|
588
|
+
entrypoints: entrypointFiles,
|
|
589
|
+
};
|
|
590
|
+
},
|
|
591
|
+
}),
|
|
659
592
|
// Moment.js is an extremely popular library that bundles large locale files
|
|
660
593
|
// by default due to how webpack interprets its code. This is a practical
|
|
661
594
|
// solution that requires the user to opt into importing specific locales.
|
|
@@ -668,61 +601,47 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
668
601
|
|
|
669
602
|
// TypeScript type checking
|
|
670
603
|
useTypeScript &&
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
:
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
604
|
+
new ForkTsCheckerWebpackPlugin({
|
|
605
|
+
async: isEnvDevelopment,
|
|
606
|
+
typescript: {
|
|
607
|
+
typescriptPath: resolve.sync('typescript', {
|
|
608
|
+
basedir: paths.appNodeModules,
|
|
609
|
+
}),
|
|
610
|
+
configOverwrite: {
|
|
611
|
+
compilerOptions: {
|
|
612
|
+
sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
|
|
613
|
+
skipLibCheck: true,
|
|
614
|
+
inlineSourceMap: false,
|
|
615
|
+
declarationMap: false,
|
|
616
|
+
noEmit: true,
|
|
617
|
+
incremental: true,
|
|
618
|
+
tsBuildInfoFile: paths.appTsBuildInfoFile,
|
|
619
|
+
},
|
|
620
|
+
},
|
|
621
|
+
context: paths.appPath,
|
|
622
|
+
diagnosticOptions: {
|
|
623
|
+
syntactic: true,
|
|
688
624
|
},
|
|
625
|
+
mode: 'write-references',
|
|
626
|
+
// profile: true,
|
|
689
627
|
},
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
628
|
+
issue: {
|
|
629
|
+
// This one is specifically to match during CI tests,
|
|
630
|
+
// as micromatch doesn't match
|
|
631
|
+
// '../cra-template-typescript/template/src/App.tsx'
|
|
632
|
+
// otherwise.
|
|
633
|
+
include: [{ file: '../**/src/**/*.{ts,tsx}' }, { file: '**/src/**/*.{ts,tsx}' }],
|
|
634
|
+
exclude: [
|
|
635
|
+
{ file: '**/src/**/__tests__/**' },
|
|
636
|
+
{ file: '**/src/**/?(*.){spec|test}.*' },
|
|
637
|
+
{ file: '**/src/setupProxy.*' },
|
|
638
|
+
{ file: '**/src/setupTests.*' },
|
|
639
|
+
],
|
|
693
640
|
},
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
// This one is specifically to match during CI tests,
|
|
699
|
-
// as micromatch doesn't match
|
|
700
|
-
// '../cra-template-typescript/template/src/App.tsx'
|
|
701
|
-
// otherwise.
|
|
702
|
-
include: [
|
|
703
|
-
{ file: '../**/src/**/*.{ts,tsx}' },
|
|
704
|
-
{ file: '**/src/**/*.{ts,tsx}' },
|
|
705
|
-
],
|
|
706
|
-
exclude: [
|
|
707
|
-
{ file: '**/src/**/__tests__/**' },
|
|
708
|
-
{ file: '**/src/**/?(*.){spec|test}.*' },
|
|
709
|
-
{ file: '**/src/setupProxy.*' },
|
|
710
|
-
{ file: '**/src/setupTests.*' },
|
|
711
|
-
],
|
|
712
|
-
},
|
|
713
|
-
logger: {
|
|
714
|
-
infrastructure: 'silent',
|
|
715
|
-
},
|
|
716
|
-
}),
|
|
717
|
-
!disableESLintPlugin &&
|
|
718
|
-
new ESLintPlugin({
|
|
719
|
-
// Plugin options
|
|
720
|
-
formatter: require.resolve('react-dev-utils/eslintFormatter'),
|
|
721
|
-
eslintPath: require.resolve('eslint'),
|
|
722
|
-
failOnError: !(isEnvDevelopment && emitErrorsAsWarnings),
|
|
723
|
-
context: paths.appSrc,
|
|
724
|
-
...eslintConfig,
|
|
725
|
-
}),
|
|
641
|
+
logger: {
|
|
642
|
+
infrastructure: 'silent',
|
|
643
|
+
},
|
|
644
|
+
}),
|
|
726
645
|
].filter(Boolean),
|
|
727
646
|
// Turn off performance processing because we utilize
|
|
728
647
|
// our own hints via the FileSizeReporter
|
|
@@ -730,7 +649,7 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
730
649
|
};
|
|
731
650
|
};
|
|
732
651
|
|
|
733
|
-
module.exports =
|
|
652
|
+
module.exports = (webpackEnv) => {
|
|
734
653
|
const baseConfig = baseConfigFactory(webpackEnv);
|
|
735
654
|
|
|
736
655
|
if (fs.existsSync(paths.webpackSetup)) {
|
|
@@ -739,7 +658,9 @@ module.exports = function (webpackEnv) {
|
|
|
739
658
|
console.log(`Using custom webpack config found in '${paths.webpackSetup}'`);
|
|
740
659
|
|
|
741
660
|
if (typeof customSetup !== 'function') {
|
|
742
|
-
throw new Error(
|
|
661
|
+
throw new Error(
|
|
662
|
+
'Custom webpack config file must export a function that accepts `env` as first parameter and `defaultConfig` as second',
|
|
663
|
+
);
|
|
743
664
|
}
|
|
744
665
|
|
|
745
666
|
return customSetup(webpackEnv, baseConfig);
|
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
// @remove-on-eject-begin
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) 2015-present, Facebook, Inc.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
*/
|
|
8
|
-
// @remove-on-eject-end
|
|
9
|
-
'use strict';
|
|
10
1
|
|
|
11
|
-
|
|
12
|
-
const
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const path = require('node:path');
|
|
13
5
|
const evalSourceMapMiddleware = require('react-dev-utils/evalSourceMapMiddleware');
|
|
14
6
|
const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware');
|
|
15
7
|
const ignoredFiles = require('react-dev-utils/ignoredFiles');
|
|
@@ -28,13 +20,12 @@ function servePreviewerIfExists() {
|
|
|
28
20
|
const previewerPath = path.dirname(require.resolve('@reactunity/previewer', { paths: [paths.appPath] }));
|
|
29
21
|
console.log('Using @reactunity/previewer');
|
|
30
22
|
return [{ directory: path.join(previewerPath, 'public') }];
|
|
31
|
-
} catch (err) {
|
|
23
|
+
} catch (err) {}
|
|
32
24
|
return [];
|
|
33
25
|
}
|
|
34
26
|
|
|
35
|
-
module.exports =
|
|
36
|
-
const disableFirewall =
|
|
37
|
-
!proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK === 'true';
|
|
27
|
+
module.exports = (proxy, allowedHost) => {
|
|
28
|
+
const disableFirewall = !proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK === 'true';
|
|
38
29
|
return {
|
|
39
30
|
// WebpackDevServer 2.4.3 introduced a security fix that prevents remote
|
|
40
31
|
// websites from potentially accessing local content through DNS rebinding:
|
|
@@ -101,7 +92,7 @@ module.exports = function (proxy, allowedHost) {
|
|
|
101
92
|
...servePreviewerIfExists(),
|
|
102
93
|
|
|
103
94
|
// Serve the fallback of web previewer as the index page
|
|
104
|
-
{ directory: path.join(__dirname, 'public')
|
|
95
|
+
{ directory: path.join(__dirname, 'public') },
|
|
105
96
|
],
|
|
106
97
|
client: {
|
|
107
98
|
webSocketURL: {
|
package/lib/types/base.d.ts
CHANGED
|
@@ -48,9 +48,7 @@ declare module '*.webp' {
|
|
|
48
48
|
declare module '*.svg' {
|
|
49
49
|
import * as React from 'react';
|
|
50
50
|
|
|
51
|
-
export const ReactComponent: React.FunctionComponent<React.SVGProps<
|
|
52
|
-
SVGSVGElement
|
|
53
|
-
> & { title?: string }>;
|
|
51
|
+
export const ReactComponent: React.FunctionComponent<React.SVGProps<SVGSVGElement> & { title?: string }>;
|
|
54
52
|
|
|
55
53
|
const src: string;
|
|
56
54
|
export default src;
|