@reactunity/scripts 0.19.1 → 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 +134 -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'),
|
|
@@ -175,9 +150,11 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
175
150
|
{
|
|
176
151
|
loader: require.resolve(preProcessor),
|
|
177
152
|
options: {
|
|
153
|
+
api: 'modern',
|
|
178
154
|
sourceMap: true,
|
|
155
|
+
warnRuleAsWarning: false,
|
|
179
156
|
},
|
|
180
|
-
}
|
|
157
|
+
},
|
|
181
158
|
);
|
|
182
159
|
}
|
|
183
160
|
return loaders;
|
|
@@ -190,9 +167,9 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
190
167
|
// Stop compilation early in production
|
|
191
168
|
bail: isEnvProduction,
|
|
192
169
|
devtool: isEnvProduction
|
|
193
|
-
?
|
|
194
|
-
?
|
|
195
|
-
: false
|
|
170
|
+
? shouldUseSourceMap
|
|
171
|
+
? sourceMapType || 'source-map'
|
|
172
|
+
: false
|
|
196
173
|
: isEnvDevelopment && (sourceMapType || 'cheap-module-source-map'),
|
|
197
174
|
// These are the "entry points" to our application.
|
|
198
175
|
// This means they will be the "root" imports that are included in JS bundle.
|
|
@@ -210,9 +187,7 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
210
187
|
// In development, it does not produce real files.
|
|
211
188
|
filename: isEnvDevelopment ? '[name].js' : process.env.FILENAME || '[name].js',
|
|
212
189
|
// There are also additional JS chunk files if you use code splitting.
|
|
213
|
-
chunkFilename: isEnvProduction
|
|
214
|
-
? 'static/js/[name].chunk.js'
|
|
215
|
-
: isEnvDevelopment && 'static/js/[name].chunk.js',
|
|
190
|
+
chunkFilename: isEnvProduction ? 'static/js/[name].chunk.js' : isEnvDevelopment && 'static/js/[name].chunk.js',
|
|
216
191
|
assetModuleFilename: 'static/media/[name][ext][ext]',
|
|
217
192
|
// webpack uses `publicPath` to determine where the app is being served from.
|
|
218
193
|
// It requires a trailing slash, or the file assets will get an incorrect path.
|
|
@@ -220,12 +195,8 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
220
195
|
publicPath: paths.publicUrlOrPath,
|
|
221
196
|
// Point sourcemap entries to original disk location (format as URL on Windows)
|
|
222
197
|
devtoolModuleFilenameTemplate: isEnvProduction
|
|
223
|
-
? info =>
|
|
224
|
-
|
|
225
|
-
.relative(paths.appSrc, info.absoluteResourcePath)
|
|
226
|
-
.replace(/\\/g, '/')
|
|
227
|
-
: isEnvDevelopment &&
|
|
228
|
-
(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, '/')),
|
|
229
200
|
},
|
|
230
201
|
cache: {
|
|
231
202
|
type: 'filesystem',
|
|
@@ -235,9 +206,7 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
235
206
|
buildDependencies: {
|
|
236
207
|
defaultWebpack: ['webpack/lib/'],
|
|
237
208
|
config: [__filename],
|
|
238
|
-
tsconfig: [paths.appTsConfig, paths.appJsConfig].filter(f =>
|
|
239
|
-
fs.existsSync(f)
|
|
240
|
-
),
|
|
209
|
+
tsconfig: [paths.appTsConfig, paths.appJsConfig].filter((f) => fs.existsSync(f)),
|
|
241
210
|
},
|
|
242
211
|
},
|
|
243
212
|
infrastructureLogging: {
|
|
@@ -296,18 +265,14 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
296
265
|
// We placed these paths second because we want `node_modules` to "win"
|
|
297
266
|
// if there are any conflicts. This matches Node resolution mechanism.
|
|
298
267
|
// https://github.com/facebook/create-react-app/issues/253
|
|
299
|
-
modules: ['node_modules', paths.appNodeModules].concat(
|
|
300
|
-
modules.additionalModulePaths || []
|
|
301
|
-
),
|
|
268
|
+
modules: ['node_modules', paths.appNodeModules].concat(modules.additionalModulePaths || []),
|
|
302
269
|
// These are the reasonable defaults supported by the Node ecosystem.
|
|
303
270
|
// We also include JSX as a common component filename extension to support
|
|
304
271
|
// some tools, although we do not recommend using it, see:
|
|
305
272
|
// https://github.com/facebook/create-react-app/issues/290
|
|
306
273
|
// `web` extension prefixes have been added for better support
|
|
307
274
|
// for React Native Web.
|
|
308
|
-
extensions: paths.moduleFileExtensions
|
|
309
|
-
.map(ext => `.${ext}`)
|
|
310
|
-
.filter(ext => useTypeScript || !ext.includes('ts')),
|
|
275
|
+
extensions: paths.moduleFileExtensions.map((ext) => `.${ext}`).filter((ext) => useTypeScript || !ext.includes('ts')),
|
|
311
276
|
alias: {
|
|
312
277
|
// Support React Native Web
|
|
313
278
|
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
|
|
@@ -334,14 +299,15 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
334
299
|
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
|
|
335
300
|
// please link the files into your node_modules/ and let module-resolution kick in.
|
|
336
301
|
// Make sure your source files are compiled, as they will not be processed in any way.
|
|
337
|
-
enableScope &&
|
|
338
|
-
paths.
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
302
|
+
enableScope &&
|
|
303
|
+
new ModuleScopePlugin(paths.appSrc, [
|
|
304
|
+
paths.appPackageJson,
|
|
305
|
+
reactRefreshRuntimeEntry,
|
|
306
|
+
reactRefreshWebpackPluginRuntimeEntry,
|
|
307
|
+
babelRuntimeEntry,
|
|
308
|
+
babelRuntimeEntryHelpers,
|
|
309
|
+
babelRuntimeRegenerator,
|
|
310
|
+
]),
|
|
345
311
|
].filter(Boolean),
|
|
346
312
|
},
|
|
347
313
|
module: {
|
|
@@ -405,9 +371,7 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
405
371
|
include: paths.appPath,
|
|
406
372
|
loader: require.resolve('babel-loader'),
|
|
407
373
|
options: {
|
|
408
|
-
customize: require.resolve(
|
|
409
|
-
'babel-preset-react-app/webpack-overrides'
|
|
410
|
-
),
|
|
374
|
+
customize: require.resolve('babel-preset-react-app/webpack-overrides'),
|
|
411
375
|
presets: [
|
|
412
376
|
[
|
|
413
377
|
require.resolve('./babel-preset-extended'),
|
|
@@ -426,23 +390,14 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
426
390
|
// We remove this when the user ejects because the default
|
|
427
391
|
// is sane and uses Babel options. Instead of options, we use
|
|
428
392
|
// the react-unity-scripts and babel-preset-react-app versions.
|
|
429
|
-
cacheIdentifier: getCacheIdentifier(
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
'babel-preset-react-app',
|
|
436
|
-
'react-dev-utils',
|
|
437
|
-
'react-unity-scripts',
|
|
438
|
-
]
|
|
439
|
-
),
|
|
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
|
+
]),
|
|
440
399
|
// @remove-on-eject-end
|
|
441
|
-
plugins: [
|
|
442
|
-
isEnvDevelopment &&
|
|
443
|
-
shouldUseReactRefresh &&
|
|
444
|
-
require.resolve('react-refresh/babel'),
|
|
445
|
-
].filter(Boolean),
|
|
400
|
+
plugins: [isEnvDevelopment && shouldUseReactRefresh && require.resolve('react-refresh/babel')].filter(Boolean),
|
|
446
401
|
// This is a feature of `babel-loader` for webpack (not Babel itself).
|
|
447
402
|
// It enables caching results in ./node_modules/.cache/babel-loader/
|
|
448
403
|
// directory for faster rebuilds.
|
|
@@ -462,27 +417,17 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
462
417
|
babelrc: true,
|
|
463
418
|
configFile: true,
|
|
464
419
|
compact: false,
|
|
465
|
-
presets: [
|
|
466
|
-
[
|
|
467
|
-
require.resolve('babel-preset-react-app/dependencies'),
|
|
468
|
-
{ helpers: true },
|
|
469
|
-
],
|
|
470
|
-
],
|
|
420
|
+
presets: [[require.resolve('babel-preset-react-app/dependencies'), { helpers: true }]],
|
|
471
421
|
cacheDirectory: true,
|
|
472
422
|
// See #6846 for context on why cacheCompression is disabled
|
|
473
423
|
cacheCompression: false,
|
|
474
424
|
// @remove-on-eject-begin
|
|
475
|
-
cacheIdentifier: getCacheIdentifier(
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
'babel-preset-react-app',
|
|
482
|
-
'react-dev-utils',
|
|
483
|
-
'react-unity-scripts',
|
|
484
|
-
]
|
|
485
|
-
),
|
|
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
|
+
]),
|
|
486
431
|
// @remove-on-eject-end
|
|
487
432
|
// Babel sourcemaps are needed for debugging into node_modules
|
|
488
433
|
// code. Without the options below, debuggers like VSCode
|
|
@@ -503,9 +448,7 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
503
448
|
exclude: cssModuleRegex,
|
|
504
449
|
use: getStyleLoaders({
|
|
505
450
|
importLoaders: 1,
|
|
506
|
-
sourceMap: isEnvProduction
|
|
507
|
-
? shouldUseSourceMap
|
|
508
|
-
: isEnvDevelopment,
|
|
451
|
+
sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
|
|
509
452
|
modules: {
|
|
510
453
|
mode: 'icss',
|
|
511
454
|
},
|
|
@@ -522,9 +465,7 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
522
465
|
test: cssModuleRegex,
|
|
523
466
|
use: getStyleLoaders({
|
|
524
467
|
importLoaders: 1,
|
|
525
|
-
sourceMap: isEnvProduction
|
|
526
|
-
? shouldUseSourceMap
|
|
527
|
-
: isEnvDevelopment,
|
|
468
|
+
sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
|
|
528
469
|
modules: {
|
|
529
470
|
mode: 'local',
|
|
530
471
|
namedExport: false,
|
|
@@ -542,14 +483,12 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
542
483
|
use: getStyleLoaders(
|
|
543
484
|
{
|
|
544
485
|
importLoaders: 3,
|
|
545
|
-
sourceMap: isEnvProduction
|
|
546
|
-
? shouldUseSourceMap
|
|
547
|
-
: isEnvDevelopment,
|
|
486
|
+
sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
|
|
548
487
|
modules: {
|
|
549
488
|
mode: 'icss',
|
|
550
489
|
},
|
|
551
490
|
},
|
|
552
|
-
'sass-loader'
|
|
491
|
+
'sass-loader',
|
|
553
492
|
),
|
|
554
493
|
// Don't consider CSS imports dead code even if the
|
|
555
494
|
// containing package claims to have no side effects.
|
|
@@ -564,9 +503,7 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
564
503
|
use: getStyleLoaders(
|
|
565
504
|
{
|
|
566
505
|
importLoaders: 3,
|
|
567
|
-
sourceMap: isEnvProduction
|
|
568
|
-
? shouldUseSourceMap
|
|
569
|
-
: isEnvDevelopment,
|
|
506
|
+
sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
|
|
570
507
|
modules: {
|
|
571
508
|
mode: 'local',
|
|
572
509
|
namedExport: false,
|
|
@@ -574,7 +511,7 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
574
511
|
getLocalIdent: getCSSModuleLocalIdent,
|
|
575
512
|
},
|
|
576
513
|
},
|
|
577
|
-
'sass-loader'
|
|
514
|
+
'sass-loader',
|
|
578
515
|
),
|
|
579
516
|
},
|
|
580
517
|
// raw-loader is added by React Unity for its usefulness and for the sake of completion
|
|
@@ -614,21 +551,21 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
614
551
|
// Experimental hot reloading for React .
|
|
615
552
|
// https://github.com/facebook/react/tree/main/packages/react-refresh
|
|
616
553
|
isEnvDevelopment &&
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
554
|
+
shouldUseReactRefresh &&
|
|
555
|
+
new ReactRefreshWebpackPlugin({
|
|
556
|
+
overlay: false,
|
|
557
|
+
}),
|
|
621
558
|
// Watcher doesn't work well if you mistype casing in a path so we use
|
|
622
559
|
// a plugin that prints an error when you attempt to do this.
|
|
623
560
|
// See https://github.com/facebook/create-react-app/issues/240
|
|
624
561
|
isEnvDevelopment && new CaseSensitivePathsPlugin(),
|
|
625
562
|
shouldExtractCss &&
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
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
|
+
}),
|
|
632
569
|
// Generate an asset manifest file with the following content:
|
|
633
570
|
// - "files" key: Mapping of all asset filenames to their corresponding
|
|
634
571
|
// output file so that tools can pick it up without having to parse
|
|
@@ -636,24 +573,22 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
636
573
|
// - "entrypoints" key: Array of files which are included in `index.html`,
|
|
637
574
|
// can be used to reconstruct the HTML if necessary
|
|
638
575
|
generateManifest &&
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
fileName => !fileName.endsWith('.map')
|
|
649
|
-
);
|
|
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'));
|
|
650
585
|
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
586
|
+
return {
|
|
587
|
+
files: manifestFiles,
|
|
588
|
+
entrypoints: entrypointFiles,
|
|
589
|
+
};
|
|
590
|
+
},
|
|
591
|
+
}),
|
|
657
592
|
// Moment.js is an extremely popular library that bundles large locale files
|
|
658
593
|
// by default due to how webpack interprets its code. This is a practical
|
|
659
594
|
// solution that requires the user to opt into importing specific locales.
|
|
@@ -666,61 +601,47 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
666
601
|
|
|
667
602
|
// TypeScript type checking
|
|
668
603
|
useTypeScript &&
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
:
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
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,
|
|
686
624
|
},
|
|
625
|
+
mode: 'write-references',
|
|
626
|
+
// profile: true,
|
|
687
627
|
},
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
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
|
+
],
|
|
691
640
|
},
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
// This one is specifically to match during CI tests,
|
|
697
|
-
// as micromatch doesn't match
|
|
698
|
-
// '../cra-template-typescript/template/src/App.tsx'
|
|
699
|
-
// otherwise.
|
|
700
|
-
include: [
|
|
701
|
-
{ file: '../**/src/**/*.{ts,tsx}' },
|
|
702
|
-
{ file: '**/src/**/*.{ts,tsx}' },
|
|
703
|
-
],
|
|
704
|
-
exclude: [
|
|
705
|
-
{ file: '**/src/**/__tests__/**' },
|
|
706
|
-
{ file: '**/src/**/?(*.){spec|test}.*' },
|
|
707
|
-
{ file: '**/src/setupProxy.*' },
|
|
708
|
-
{ file: '**/src/setupTests.*' },
|
|
709
|
-
],
|
|
710
|
-
},
|
|
711
|
-
logger: {
|
|
712
|
-
infrastructure: 'silent',
|
|
713
|
-
},
|
|
714
|
-
}),
|
|
715
|
-
!disableESLintPlugin &&
|
|
716
|
-
new ESLintPlugin({
|
|
717
|
-
// Plugin options
|
|
718
|
-
formatter: require.resolve('react-dev-utils/eslintFormatter'),
|
|
719
|
-
eslintPath: require.resolve('eslint'),
|
|
720
|
-
failOnError: !(isEnvDevelopment && emitErrorsAsWarnings),
|
|
721
|
-
context: paths.appSrc,
|
|
722
|
-
...eslintConfig,
|
|
723
|
-
}),
|
|
641
|
+
logger: {
|
|
642
|
+
infrastructure: 'silent',
|
|
643
|
+
},
|
|
644
|
+
}),
|
|
724
645
|
].filter(Boolean),
|
|
725
646
|
// Turn off performance processing because we utilize
|
|
726
647
|
// our own hints via the FileSizeReporter
|
|
@@ -728,7 +649,7 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
728
649
|
};
|
|
729
650
|
};
|
|
730
651
|
|
|
731
|
-
module.exports =
|
|
652
|
+
module.exports = (webpackEnv) => {
|
|
732
653
|
const baseConfig = baseConfigFactory(webpackEnv);
|
|
733
654
|
|
|
734
655
|
if (fs.existsSync(paths.webpackSetup)) {
|
|
@@ -737,7 +658,9 @@ module.exports = function (webpackEnv) {
|
|
|
737
658
|
console.log(`Using custom webpack config found in '${paths.webpackSetup}'`);
|
|
738
659
|
|
|
739
660
|
if (typeof customSetup !== 'function') {
|
|
740
|
-
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
|
+
);
|
|
741
664
|
}
|
|
742
665
|
|
|
743
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;
|