@reactunity/scripts 0.9.0 → 0.11.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/README.md +7 -3
- package/bin/react-unity-scripts.js +2 -1
- package/config/env.js +2 -2
- package/config/paths.js +10 -0
- package/config/{web-inspector → public}/.gitignore +0 -0
- package/config/{web-inspector → public}/favicon.ico +0 -0
- package/config/public/index.html +78 -0
- package/config/webpack.config.js +63 -6
- package/config/webpackDevServer.config.js +23 -6
- package/package.json +46 -51
- package/scripts/build.js +3 -15
- package/scripts/clean.js +34 -0
- package/scripts/init.js +5 -5
- package/scripts/start.js +0 -9
- package/scripts/utils/cleanBuildDirectory.js +76 -0
- package/config/web-inspector/Build/WebInspector.data +0 -0
- package/config/web-inspector/Build/WebInspector.framework.js +0 -7
- package/config/web-inspector/Build/WebInspector.loader.js +0 -1
- package/config/web-inspector/Build/WebInspector.wasm +0 -0
- package/config/web-inspector/index.html +0 -86
package/README.md
CHANGED
|
@@ -25,15 +25,19 @@ Environment variables of CRA can be used with React Unity. However, there are so
|
|
|
25
25
|
- `FILENAME` - Name of the generated javascript file. `index.js` by default.
|
|
26
26
|
- `BUILD_PATH` - Path to the generated output. Relative to the project. `../Assets/Resources/react` by default.
|
|
27
27
|
- `GENERATE_SOURCEMAP` - `false` by default.
|
|
28
|
-
- `
|
|
28
|
+
- `FAST_REFRESH` - This can be set to `false` to disable `react-refresh` if you are having problems with hot reload
|
|
29
29
|
- `IMAGE_INLINE_SIZE_LIMIT` - `0` by default. Because non-inlined images will be faster in Unity. However, if users still want to inline images, they should increase this limit.
|
|
30
30
|
|
|
31
31
|
Environment variables can also be defined by having `.env`, `.env.local`, `.env.<development|production>` in project folder.
|
|
32
32
|
|
|
33
33
|
Custom environment variables are also possible as in [CRA](https://create-react-app.dev/docs/adding-custom-environment-variables).
|
|
34
34
|
|
|
35
|
+
## Multiple Entry Points
|
|
36
|
+
|
|
37
|
+
In addition to `src/index` file, there can be other entry points. Every file under `src/entry/` folder will be detected and configured as an entry point. For example, if there is a file `src/entry/menu.tsx`, Webpack will detect that and create an entrypoint named `menu` with output `menu.js` in addition to the default entrypoint `index.js`.
|
|
38
|
+
|
|
35
39
|
## WebGL Inspector
|
|
36
40
|
|
|
37
|
-
When dev server is started with the `start` script, a web server is launched at the selected port (e.g. http://localhost:3000). This server serves the javascript and asset files that are used by ReactUnity. If you visit this link in browser, you will see a
|
|
41
|
+
When dev server is started with the `start` script, a web server is launched at the selected port (e.g. http://localhost:3000). This server serves the javascript and asset files that are used by ReactUnity. If you visit this link in browser, you will see a page explaining how to setup the web previewer. The previewer can be used to quickly test the React code without even launching Unity. It also reacts to the changes in code by utilizing HMR.
|
|
38
42
|
|
|
39
|
-
Note that this web inspector has very limited capabilities. Naturally, it may not work for all cases. However it is a useful tool for when starting a new ReactUnity project. As an advanced feature, you can override the web inspector by placing your custom web inspector in `
|
|
43
|
+
Note that this web inspector has very limited capabilities. Naturally, it may not work for all cases. However it is a useful tool for when starting a new ReactUnity project. As an advanced feature, you can override the web inspector by placing your custom web inspector in `previewer` folder under your React project.
|
|
@@ -24,12 +24,13 @@ const scriptIndex = args.findIndex(
|
|
|
24
24
|
x === 'eject' ||
|
|
25
25
|
x === 'start' ||
|
|
26
26
|
x === 'test' ||
|
|
27
|
+
x === 'clean' ||
|
|
27
28
|
x === 'lint'
|
|
28
29
|
);
|
|
29
30
|
const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
|
|
30
31
|
const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
|
|
31
32
|
|
|
32
|
-
if (['build', 'eject', 'start', 'test', 'lint'].includes(script)) {
|
|
33
|
+
if (['build', 'eject', 'start', 'test', 'clean', 'lint'].includes(script)) {
|
|
33
34
|
const result = spawn.sync(
|
|
34
35
|
process.execPath,
|
|
35
36
|
nodeArgs
|
package/config/env.js
CHANGED
|
@@ -40,7 +40,7 @@ const dotenvFiles = [
|
|
|
40
40
|
// https://github.com/motdotla/dotenv-expand
|
|
41
41
|
dotenvFiles.forEach(dotenvFile => {
|
|
42
42
|
if (fs.existsSync(dotenvFile)) {
|
|
43
|
-
require('dotenv-expand')(
|
|
43
|
+
require('dotenv-expand').expand(
|
|
44
44
|
require('dotenv').config({
|
|
45
45
|
path: dotenvFile,
|
|
46
46
|
})
|
|
@@ -95,7 +95,7 @@ function getClientEnvironment(publicUrl) {
|
|
|
95
95
|
WDS_SOCKET_PORT: process.env.WDS_SOCKET_PORT,
|
|
96
96
|
// Whether or not react-refresh is enabled.
|
|
97
97
|
// It is defined here so it is available in the webpackHotDevClient.
|
|
98
|
-
FAST_REFRESH: process.env.FAST_REFRESH
|
|
98
|
+
FAST_REFRESH: process.env.FAST_REFRESH !== 'false',
|
|
99
99
|
}
|
|
100
100
|
);
|
|
101
101
|
// Stringify all values so we can feed into webpack DefinePlugin
|
package/config/paths.js
CHANGED
|
@@ -30,6 +30,7 @@ const publicUrlOrPath = getPublicUrlOrPath(
|
|
|
30
30
|
);
|
|
31
31
|
|
|
32
32
|
const buildPath = process.env.BUILD_PATH || '../Assets/Resources/react';
|
|
33
|
+
const manifestPath = path.join(buildPath, 'asset-manifest.json');
|
|
33
34
|
|
|
34
35
|
const moduleFileExtensions = [
|
|
35
36
|
'web.mjs',
|
|
@@ -63,7 +64,9 @@ module.exports = {
|
|
|
63
64
|
dotenv: resolveApp('.env'),
|
|
64
65
|
appPath: resolveApp('.'),
|
|
65
66
|
appBuild: resolveApp(buildPath),
|
|
67
|
+
appManifest: resolveApp(manifestPath),
|
|
66
68
|
appPublic: resolveApp('public'),
|
|
69
|
+
appPublicAlt: resolveApp('previewer'),
|
|
67
70
|
appHtml: resolveApp('public/index.html'),
|
|
68
71
|
appIndexJs: resolveModule(resolveApp, 'src/index'),
|
|
69
72
|
appPackageJson: resolveApp('package.json'),
|
|
@@ -73,6 +76,7 @@ module.exports = {
|
|
|
73
76
|
yarnLockFile: resolveApp('yarn.lock'),
|
|
74
77
|
testsSetup: resolveModule(resolveApp, 'src/setupTests'),
|
|
75
78
|
proxySetup: resolveApp('src/setupProxy.js'),
|
|
79
|
+
webpackSetup: resolveApp('webpack.config.js'),
|
|
76
80
|
appNodeModules: resolveApp('node_modules'),
|
|
77
81
|
appWebpackCache: resolveApp('node_modules/.cache'),
|
|
78
82
|
appTsBuildInfoFile: resolveApp('node_modules/.cache/tsconfig.tsbuildinfo'),
|
|
@@ -88,7 +92,9 @@ module.exports = {
|
|
|
88
92
|
dotenv: resolveApp('.env'),
|
|
89
93
|
appPath: resolveApp('.'),
|
|
90
94
|
appBuild: resolveApp(buildPath),
|
|
95
|
+
appManifest: resolveApp(manifestPath),
|
|
91
96
|
appPublic: resolveApp('public'),
|
|
97
|
+
appPublicAlt: resolveApp('previewer'),
|
|
92
98
|
appHtml: resolveApp('public/index.html'),
|
|
93
99
|
appIndexJs: resolveModule(resolveApp, 'src/index'),
|
|
94
100
|
appPackageJson: resolveApp('package.json'),
|
|
@@ -98,6 +104,7 @@ module.exports = {
|
|
|
98
104
|
yarnLockFile: resolveApp('yarn.lock'),
|
|
99
105
|
testsSetup: resolveModule(resolveApp, 'src/setupTests'),
|
|
100
106
|
proxySetup: resolveApp('src/setupProxy.js'),
|
|
107
|
+
webpackSetup: resolveApp('webpack.config.js'),
|
|
101
108
|
appNodeModules: resolveApp('node_modules'),
|
|
102
109
|
appWebpackCache: resolveApp('node_modules/.cache'),
|
|
103
110
|
appTsBuildInfoFile: resolveApp('node_modules/.cache/tsconfig.tsbuildinfo'),
|
|
@@ -126,7 +133,9 @@ if (
|
|
|
126
133
|
dotenv: resolveOwn(`${templatePath}/.env`),
|
|
127
134
|
appPath: resolveApp('.'),
|
|
128
135
|
appBuild: resolveOwn(path.join('../..', buildPath)),
|
|
136
|
+
appManifest: resolveOwn(path.join('../..', manifestPath)),
|
|
129
137
|
appPublic: resolveOwn(`${templatePath}/public`),
|
|
138
|
+
appPreviewer: resolveOwn(`${templatePath}/previewer`),
|
|
130
139
|
appHtml: resolveOwn(`${templatePath}/public/index.html`),
|
|
131
140
|
appIndexJs: resolveModule(resolveOwn, `${templatePath}/src/index`),
|
|
132
141
|
appPackageJson: resolveOwn('package.json'),
|
|
@@ -136,6 +145,7 @@ if (
|
|
|
136
145
|
yarnLockFile: resolveOwn(`${templatePath}/yarn.lock`),
|
|
137
146
|
testsSetup: resolveModule(resolveOwn, `${templatePath}/src/setupTests`),
|
|
138
147
|
proxySetup: resolveOwn(`${templatePath}/src/setupProxy.js`),
|
|
148
|
+
webpackSetup: resolveApp(`${templatePath}/webpack.config.js`),
|
|
139
149
|
appNodeModules: resolveOwn('node_modules'),
|
|
140
150
|
appWebpackCache: resolveOwn('node_modules/.cache'),
|
|
141
151
|
appTsBuildInfoFile: resolveOwn('node_modules/.cache/tsconfig.tsbuildinfo'),
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en-us">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
8
|
+
|
|
9
|
+
<title>ReactUnity</title>
|
|
10
|
+
|
|
11
|
+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
|
|
12
|
+
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
|
|
13
|
+
</head>
|
|
14
|
+
|
|
15
|
+
<body>
|
|
16
|
+
|
|
17
|
+
<div class="col-lg-8 mx-auto p-3 py-md-5">
|
|
18
|
+
<header class="d-flex align-items-center pb-3 mb-5 border-bottom">
|
|
19
|
+
<a href="/" class="d-flex align-items-center text-dark text-decoration-none">
|
|
20
|
+
<img src="./favicon.ico" height="72" class="me-3" />
|
|
21
|
+
<span class="fs-1">ReactUnity Previewer</span>
|
|
22
|
+
</a>
|
|
23
|
+
</header>
|
|
24
|
+
|
|
25
|
+
<main>
|
|
26
|
+
<p class="fs-5 col-md-8">
|
|
27
|
+
Congratulations on starting your ReactUnity project. You can now test your app inside Unity by setting the
|
|
28
|
+
<code>DevServer</code> property of <code>ReactUnityUGUI</code> or <code>ReactUnityUIToolkit</code> components to
|
|
29
|
+
the address of this page.
|
|
30
|
+
</p>
|
|
31
|
+
|
|
32
|
+
<p class="fs-5 col-md-8">
|
|
33
|
+
If your UI is simple, you can also test your UI inside this page with a WebGL template. There are 2 ways you can
|
|
34
|
+
do that.
|
|
35
|
+
</p>
|
|
36
|
+
|
|
37
|
+
<div class="alert alert-warning d-flex align-items-center" role="alert">
|
|
38
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor"
|
|
39
|
+
class="bi bi-exclamation-triangle-fill flex-shrink-0 me-2" viewBox="0 0 16 16" role="img"
|
|
40
|
+
aria-label="Warning:">
|
|
41
|
+
<path
|
|
42
|
+
d="M8.982 1.566a1.13 1.13 0 0 0-1.96 0L.165 13.233c-.457.778.091 1.767.98 1.767h13.713c.889 0 1.438-.99.98-1.767L8.982 1.566zM8 5c.535 0 .954.462.9.995l-.35 3.507a.552.552 0 0 1-1.1 0L7.1 5.995A.905.905 0 0 1 8 5zm.002 6a1 1 0 1 1 0 2 1 1 0 0 1 0-2z" />
|
|
43
|
+
</svg>
|
|
44
|
+
<div class="fs-5">
|
|
45
|
+
Note that as ReactUnity is not optimized for WebGL, you will have a low performance by testing in WebGL.
|
|
46
|
+
</div>
|
|
47
|
+
</div>
|
|
48
|
+
|
|
49
|
+
<h4>1 - Install the default previewer</h4>
|
|
50
|
+
|
|
51
|
+
<p class="fs-5 col-md-8">
|
|
52
|
+
You can install the <code>@reactunity/previewer</code> package for this.
|
|
53
|
+
</p>
|
|
54
|
+
|
|
55
|
+
<pre>
|
|
56
|
+
yarn add --dev @reactunity/previewer
|
|
57
|
+
# OR
|
|
58
|
+
npm i --D @reactunity/previewer
|
|
59
|
+
</pre>
|
|
60
|
+
|
|
61
|
+
<h4>2 - Use a custom previewer</h4>
|
|
62
|
+
|
|
63
|
+
<p class="fs-5 col-md-8">
|
|
64
|
+
To do this, you need to build a scene in Unity with <code>ReactUnityUGUI</code> component added. The
|
|
65
|
+
<code>Type</code> property must be set to <code>Url</code> and <code>Source Path</code> property must be set to
|
|
66
|
+
<code>/index.js</code>.
|
|
67
|
+
|
|
68
|
+
After building, you must copy the built directory to <code>previewer</code> folder inside your React project, so
|
|
69
|
+
that there is a <code>previewer/index.html</code> file.
|
|
70
|
+
</p>
|
|
71
|
+
</main>
|
|
72
|
+
|
|
73
|
+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js"
|
|
74
|
+
integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF"
|
|
75
|
+
crossorigin="anonymous"></script>
|
|
76
|
+
</body>
|
|
77
|
+
|
|
78
|
+
</html>
|
package/config/webpack.config.js
CHANGED
|
@@ -74,15 +74,42 @@ const useTailwind = fs.existsSync(
|
|
|
74
74
|
path.join(paths.appPath, 'tailwind.config.js')
|
|
75
75
|
);
|
|
76
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
|
+
|
|
77
91
|
// style files regexes
|
|
78
92
|
const cssRegex = /\.css$/;
|
|
79
93
|
const cssModuleRegex = /\.module\.css$/;
|
|
80
94
|
const sassRegex = /\.(scss|sass)$/;
|
|
81
95
|
const sassModuleRegex = /\.module\.(scss|sass)$/;
|
|
82
96
|
|
|
97
|
+
|
|
98
|
+
// Treat files under `src/entry` as separate entry points
|
|
99
|
+
const appDirectory = fs.realpathSync(process.cwd());
|
|
100
|
+
const entryDirectory = path.join(appDirectory, 'src/entry');
|
|
101
|
+
const entries = !fs.existsSync(entryDirectory) ? [] :
|
|
102
|
+
fs.readdirSync(entryDirectory, { withFileTypes: true })
|
|
103
|
+
.filter(x => x.isFile())
|
|
104
|
+
.filter(x => /\.(js|mjs|jsx|ts|tsx)$/.test(x.name))
|
|
105
|
+
.map(x => path.resolve(entryDirectory, x.name));
|
|
106
|
+
const entryObj = {};
|
|
107
|
+
for (const entry of entries) entryObj[path.basename(entry, path.extname(entry))] = entry;
|
|
108
|
+
|
|
109
|
+
|
|
83
110
|
// This is the production and development configuration.
|
|
84
111
|
// It is focused on developer experience, fast rebuilds, and a minimal bundle.
|
|
85
|
-
|
|
112
|
+
const baseConfigFactory = function (webpackEnv) {
|
|
86
113
|
const isEnvDevelopment = webpackEnv === 'development';
|
|
87
114
|
const isEnvProduction = webpackEnv === 'production';
|
|
88
115
|
const shouldExtractCss = isEnvProduction && extractCss;
|
|
@@ -127,7 +154,13 @@ module.exports = function (webpackEnv) {
|
|
|
127
154
|
// https://github.com/facebook/create-react-app/issues/2677
|
|
128
155
|
ident: 'postcss',
|
|
129
156
|
config: false,
|
|
130
|
-
plugins:
|
|
157
|
+
plugins: {
|
|
158
|
+
...usePostcssPluginIfExists('postcss-import'),
|
|
159
|
+
'tailwindcss': {},
|
|
160
|
+
...usePostcssPluginIfExists('postcss-nesting'),
|
|
161
|
+
...usePostcssPluginIfExists('postcss-custom-properties'),
|
|
162
|
+
...usePostcssPluginIfExists('postcss-css-variables'),
|
|
163
|
+
},
|
|
131
164
|
},
|
|
132
165
|
sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
|
|
133
166
|
},
|
|
@@ -164,15 +197,18 @@ module.exports = function (webpackEnv) {
|
|
|
164
197
|
: isEnvDevelopment && (sourceMapType || 'eval-source-map'),
|
|
165
198
|
// These are the "entry points" to our application.
|
|
166
199
|
// This means they will be the "root" imports that are included in JS bundle.
|
|
167
|
-
entry:
|
|
200
|
+
entry: {
|
|
201
|
+
index: paths.appIndexJs,
|
|
202
|
+
...entryObj,
|
|
203
|
+
},
|
|
168
204
|
output: {
|
|
169
205
|
// The build folder.
|
|
170
206
|
path: paths.appBuild,
|
|
171
207
|
// Add /* filename */ comments to generated require()s in the output.
|
|
172
208
|
pathinfo: isEnvDevelopment,
|
|
173
|
-
// There
|
|
209
|
+
// There can be multiple entry bundles, and one file per asynchronous chunk.
|
|
174
210
|
// In development, it does not produce real files.
|
|
175
|
-
filename: isEnvDevelopment ? '
|
|
211
|
+
filename: isEnvDevelopment ? '[name].js' : process.env.FILENAME || '[name].js',
|
|
176
212
|
// There are also additional JS chunk files if you use code splitting.
|
|
177
213
|
chunkFilename: isEnvProduction
|
|
178
214
|
? 'static/js/[name].chunk.js'
|
|
@@ -282,6 +318,9 @@ module.exports = function (webpackEnv) {
|
|
|
282
318
|
'react-dom$': 'react-dom/profiling',
|
|
283
319
|
'scheduler/tracing': 'scheduler/tracing-profiling',
|
|
284
320
|
}),
|
|
321
|
+
// Allows replacing react-dom with @reactunity/renderer to support some functionality like `unstable_batchedUpdates`
|
|
322
|
+
'react-dom': '@reactunity/renderer',
|
|
323
|
+
|
|
285
324
|
...(modules.webpackAliases || {}),
|
|
286
325
|
},
|
|
287
326
|
plugins: [
|
|
@@ -567,7 +606,7 @@ module.exports = function (webpackEnv) {
|
|
|
567
606
|
manifest[file.name] = file.path;
|
|
568
607
|
return manifest;
|
|
569
608
|
}, seed);
|
|
570
|
-
const entrypointFiles = entrypoints.
|
|
609
|
+
const entrypointFiles = entrypoints.index.filter(
|
|
571
610
|
fileName => !fileName.endsWith('.map')
|
|
572
611
|
);
|
|
573
612
|
|
|
@@ -650,3 +689,21 @@ module.exports = function (webpackEnv) {
|
|
|
650
689
|
performance: false,
|
|
651
690
|
};
|
|
652
691
|
};
|
|
692
|
+
|
|
693
|
+
module.exports = function (webpackEnv) {
|
|
694
|
+
const baseConfig = baseConfigFactory(webpackEnv);
|
|
695
|
+
|
|
696
|
+
if (fs.existsSync(paths.webpackSetup)) {
|
|
697
|
+
const customSetup = require(paths.webpackSetup);
|
|
698
|
+
|
|
699
|
+
console.log(`Using custom webpack config found in '${paths.webpackSetup}'`);
|
|
700
|
+
|
|
701
|
+
if (typeof customSetup !== 'function') {
|
|
702
|
+
throw new Error('Custom webpack config file must export a function that accepts `env` as first parameter and `defaultConfig` as second');
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
return customSetup(webpackEnv, baseConfig);
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
return baseConfig;
|
|
709
|
+
};
|
|
@@ -23,6 +23,15 @@ const sockHost = process.env.WDS_SOCKET_HOST;
|
|
|
23
23
|
const sockPath = process.env.WDS_SOCKET_PATH; // default: '/ws'
|
|
24
24
|
const sockPort = process.env.WDS_SOCKET_PORT;
|
|
25
25
|
|
|
26
|
+
function servePreviewerIfExists() {
|
|
27
|
+
try {
|
|
28
|
+
const previewerPath = path.dirname(require.resolve('@reactunity/previewer', { paths: [paths.appPath] }));
|
|
29
|
+
console.log('Using @reactunity/previewer');
|
|
30
|
+
return [{ directory: path.join(previewerPath, 'public') }];
|
|
31
|
+
} catch (err) { }
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
|
|
26
35
|
module.exports = function (proxy, allowedHost) {
|
|
27
36
|
const disableFirewall =
|
|
28
37
|
!proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK === 'true';
|
|
@@ -54,8 +63,6 @@ module.exports = function (proxy, allowedHost) {
|
|
|
54
63
|
// Enable gzip compression of generated files.
|
|
55
64
|
compress: true,
|
|
56
65
|
static: [
|
|
57
|
-
// Serve React Unity Web Inspector as the index page
|
|
58
|
-
{ directory: path.join(__dirname, 'web-inspector'), },
|
|
59
66
|
{
|
|
60
67
|
// By default WebpackDevServer serves physical files from current directory
|
|
61
68
|
// in addition to all the virtual build products that it serves from memory.
|
|
@@ -82,6 +89,19 @@ module.exports = function (proxy, allowedHost) {
|
|
|
82
89
|
ignored: ignoredFiles(paths.appSrc),
|
|
83
90
|
},
|
|
84
91
|
},
|
|
92
|
+
|
|
93
|
+
// Serve previewer from local previewer directory
|
|
94
|
+
{
|
|
95
|
+
directory: paths.appPreviewer,
|
|
96
|
+
publicPath: [paths.publicUrlOrPath],
|
|
97
|
+
watch: { ignored: ignoredFiles(paths.appSrc) },
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
// If installed, serve the ReactUnity Web Previewer
|
|
101
|
+
...servePreviewerIfExists(),
|
|
102
|
+
|
|
103
|
+
// Serve the fallback of web previewer as the index page
|
|
104
|
+
{ directory: path.join(__dirname, 'public'), },
|
|
85
105
|
],
|
|
86
106
|
|
|
87
107
|
client: {
|
|
@@ -93,10 +113,7 @@ module.exports = function (proxy, allowedHost) {
|
|
|
93
113
|
pathname: sockPath,
|
|
94
114
|
port: sockPort,
|
|
95
115
|
},
|
|
96
|
-
overlay:
|
|
97
|
-
errors: true,
|
|
98
|
-
warnings: false,
|
|
99
|
-
},
|
|
116
|
+
overlay: false,
|
|
100
117
|
},
|
|
101
118
|
devMiddleware: {
|
|
102
119
|
// It is important to tell WebpackDevServer to use the same "publicPath" path as
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactunity/scripts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Configuration and scripts for React Unity.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -44,83 +44,78 @@
|
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@babel/core": "^7.
|
|
48
|
-
"@babel/eslint-parser": "^7.
|
|
49
|
-
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.
|
|
50
|
-
"@types/react": "^
|
|
51
|
-
"@types/webpack-env": "^1.16.
|
|
52
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
53
|
-
"@typescript-eslint/parser": "^5.
|
|
54
|
-
"babel-jest": "^
|
|
55
|
-
"babel-loader": "^8.2.
|
|
47
|
+
"@babel/core": "^7.17.10",
|
|
48
|
+
"@babel/eslint-parser": "^7.17.0",
|
|
49
|
+
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.5",
|
|
50
|
+
"@types/react": "^18.0.9",
|
|
51
|
+
"@types/webpack-env": "^1.16.4",
|
|
52
|
+
"@typescript-eslint/eslint-plugin": "^5.22.0",
|
|
53
|
+
"@typescript-eslint/parser": "^5.22.0",
|
|
54
|
+
"babel-jest": "^28.1.0",
|
|
55
|
+
"babel-loader": "^8.2.5",
|
|
56
56
|
"babel-plugin-named-asset-import": "^0.3.8",
|
|
57
57
|
"babel-preset-react-app": "^10.0.1",
|
|
58
58
|
"bfj": "^7.0.2",
|
|
59
59
|
"camelcase": "^6.3.0",
|
|
60
60
|
"case-sensitive-paths-webpack-plugin": "^2.4.0",
|
|
61
61
|
"confusing-browser-globals": "^1.0.11",
|
|
62
|
-
"css-loader": "^6.
|
|
63
|
-
"dotenv": "^
|
|
64
|
-
"dotenv-expand": "^
|
|
65
|
-
"eslint": "^8.
|
|
66
|
-
"eslint-plugin-import": "^2.
|
|
67
|
-
"eslint-plugin-jest": "^
|
|
68
|
-
"eslint-plugin-react": "^7.
|
|
69
|
-
"eslint-plugin-react-hooks": "^4.
|
|
70
|
-
"eslint-plugin-testing-library": "^5.0
|
|
62
|
+
"css-loader": "^6.7.1",
|
|
63
|
+
"dotenv": "^16.0.0",
|
|
64
|
+
"dotenv-expand": "^8.0.3",
|
|
65
|
+
"eslint": "^8.15.0",
|
|
66
|
+
"eslint-plugin-import": "^2.26.0",
|
|
67
|
+
"eslint-plugin-jest": "^26.1.5",
|
|
68
|
+
"eslint-plugin-react": "^7.29.4",
|
|
69
|
+
"eslint-plugin-react-hooks": "^4.5.0",
|
|
70
|
+
"eslint-plugin-testing-library": "^5.4.0",
|
|
71
71
|
"eslint-webpack-plugin": "^3.1.1",
|
|
72
72
|
"file-loader": "^6.2.0",
|
|
73
|
-
"fs-extra": "^10.
|
|
73
|
+
"fs-extra": "^10.1.0",
|
|
74
74
|
"identity-obj-proxy": "^3.0.0",
|
|
75
|
-
"jest": "^
|
|
76
|
-
"jest-resolve": "^
|
|
77
|
-
"jest-watch-typeahead": "^1.
|
|
78
|
-
"mini-css-extract-plugin": "^2.
|
|
75
|
+
"jest": "^28.1.0",
|
|
76
|
+
"jest-resolve": "^28.1.0",
|
|
77
|
+
"jest-watch-typeahead": "^1.1.0",
|
|
78
|
+
"mini-css-extract-plugin": "^2.6.0",
|
|
79
79
|
"null-loader": "^4.0.1",
|
|
80
|
-
"postcss": "^8.4.
|
|
80
|
+
"postcss": "^8.4.13",
|
|
81
81
|
"postcss-loader": "^6.2.1",
|
|
82
82
|
"prompts": "^2.4.2",
|
|
83
83
|
"raw-loader": "^4.0.2",
|
|
84
84
|
"react-app-polyfill": "^3.0.0",
|
|
85
|
-
"react-dev-utils": "^12.0.
|
|
86
|
-
"react-refresh": "^0.
|
|
87
|
-
"resolve": "^1.
|
|
88
|
-
"resolve-url-loader": "^
|
|
89
|
-
"sass": "^1.
|
|
90
|
-
"sass-loader": "^12.
|
|
91
|
-
"semver": "^7.3.
|
|
85
|
+
"react-dev-utils": "^12.0.1",
|
|
86
|
+
"react-refresh": "^0.13.0",
|
|
87
|
+
"resolve": "^1.22.0",
|
|
88
|
+
"resolve-url-loader": "^5.0.0",
|
|
89
|
+
"sass": "^1.51.0",
|
|
90
|
+
"sass-loader": "^12.6.0",
|
|
91
|
+
"semver": "^7.3.7",
|
|
92
92
|
"source-map-loader": "^3.0.1",
|
|
93
93
|
"style-loader": "^3.3.1",
|
|
94
|
-
"tailwindcss": "^3.0.
|
|
95
|
-
"terser-webpack-plugin": "^5.3.
|
|
94
|
+
"tailwindcss": "^3.0.24",
|
|
95
|
+
"terser-webpack-plugin": "^5.3.1",
|
|
96
96
|
"url-loader": "^4.1.1",
|
|
97
|
-
"webpack": "^5.
|
|
98
|
-
"webpack-dev-server": "^4.
|
|
99
|
-
"webpack-manifest-plugin": "^
|
|
97
|
+
"webpack": "^5.72.0",
|
|
98
|
+
"webpack-dev-server": "^4.9.0",
|
|
99
|
+
"webpack-manifest-plugin": "^5.0.0"
|
|
100
100
|
},
|
|
101
101
|
"devDependencies": {
|
|
102
|
-
"
|
|
103
|
-
"typescript": "^4.5.4"
|
|
102
|
+
"typescript": "^4.6.4"
|
|
104
103
|
},
|
|
105
104
|
"optionalDependencies": {
|
|
106
105
|
"fsevents": "^2.3.2"
|
|
107
106
|
},
|
|
108
107
|
"peerDependencies": {
|
|
109
|
-
"@reactunity/
|
|
110
|
-
"
|
|
111
|
-
"
|
|
108
|
+
"@reactunity/previewer": "*",
|
|
109
|
+
"@reactunity/renderer": "^0.11.0",
|
|
110
|
+
"react": "^18.0.0",
|
|
111
|
+
"typescript": "^4.6.4"
|
|
112
112
|
},
|
|
113
113
|
"peerDependenciesMeta": {
|
|
114
|
+
"@reactunity/previewer": {
|
|
115
|
+
"optional": true
|
|
116
|
+
},
|
|
114
117
|
"typescript": {
|
|
115
118
|
"optional": true
|
|
116
119
|
}
|
|
117
|
-
}
|
|
118
|
-
"bundledDependencies": [
|
|
119
|
-
"@typescript-eslint/eslint-plugin",
|
|
120
|
-
"eslint-plugin-import",
|
|
121
|
-
"eslint-plugin-jest",
|
|
122
|
-
"eslint-plugin-react",
|
|
123
|
-
"eslint-plugin-react-hooks",
|
|
124
|
-
"eslint-plugin-testing-library"
|
|
125
|
-
]
|
|
120
|
+
}
|
|
126
121
|
}
|
package/scripts/build.js
CHANGED
|
@@ -31,14 +31,13 @@ const configFactory = require('../config/webpack.config');
|
|
|
31
31
|
const paths = require('../config/paths');
|
|
32
32
|
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
|
|
33
33
|
const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages');
|
|
34
|
-
const printHostingInstructions = require('react-dev-utils/printHostingInstructions');
|
|
35
34
|
const FileSizeReporter = require('react-dev-utils/FileSizeReporter');
|
|
36
35
|
const printBuildError = require('react-dev-utils/printBuildError');
|
|
36
|
+
const { cleanBuildDirectory } = require('./utils/cleanBuildDirectory');
|
|
37
37
|
|
|
38
38
|
const measureFileSizesBeforeBuild =
|
|
39
39
|
FileSizeReporter.measureFileSizesBeforeBuild;
|
|
40
40
|
const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild;
|
|
41
|
-
const useYarn = fs.existsSync(paths.yarnLockFile);
|
|
42
41
|
|
|
43
42
|
// These sizes are pretty large. We'll warn for bundles exceeding them.
|
|
44
43
|
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
|
|
@@ -67,9 +66,7 @@ checkBrowsers(paths.appPath, isInteractive)
|
|
|
67
66
|
return measureFileSizesBeforeBuild(paths.appBuild);
|
|
68
67
|
})
|
|
69
68
|
.then(previousFileSizes => {
|
|
70
|
-
|
|
71
|
-
// if you're in it, you don't end up in Trash
|
|
72
|
-
fs.emptyDirSync(paths.appBuild);
|
|
69
|
+
cleanBuildDirectory();
|
|
73
70
|
// Merge with the public folder
|
|
74
71
|
copyPublicFolder();
|
|
75
72
|
// Start the webpack build
|
|
@@ -104,17 +101,8 @@ checkBrowsers(paths.appPath, isInteractive)
|
|
|
104
101
|
);
|
|
105
102
|
console.log();
|
|
106
103
|
|
|
107
|
-
const appPackage = require(paths.appPackageJson);
|
|
108
|
-
const publicUrl = paths.publicUrlOrPath;
|
|
109
|
-
const publicPath = config.output.publicPath;
|
|
110
104
|
const buildFolder = path.relative(process.cwd(), paths.appBuild);
|
|
111
|
-
|
|
112
|
-
appPackage,
|
|
113
|
-
publicUrl,
|
|
114
|
-
publicPath,
|
|
115
|
-
buildFolder,
|
|
116
|
-
useYarn
|
|
117
|
-
);
|
|
105
|
+
console.log(`The ${chalk.blue(buildFolder)} folder is ready to be used in ReactUnity.`);
|
|
118
106
|
},
|
|
119
107
|
err => {
|
|
120
108
|
const tscCompileOnError = process.env.TSC_COMPILE_ON_ERROR === 'true';
|
package/scripts/clean.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
|
|
11
|
+
// Do this as the first thing so that any code reading it knows the right env.
|
|
12
|
+
process.env.BABEL_ENV = 'production';
|
|
13
|
+
process.env.NODE_ENV = 'production';
|
|
14
|
+
|
|
15
|
+
// Makes the script crash on unhandled rejections instead of silently
|
|
16
|
+
// ignoring them. In the future, promise rejections that are not handled will
|
|
17
|
+
// terminate the Node.js process with a non-zero exit code.
|
|
18
|
+
process.on('unhandledRejection', err => {
|
|
19
|
+
throw err;
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Ensure environment variables are read.
|
|
23
|
+
require('../config/env');
|
|
24
|
+
|
|
25
|
+
const path = require('path');
|
|
26
|
+
const chalk = require('react-dev-utils/chalk');
|
|
27
|
+
const paths = require('../config/paths');
|
|
28
|
+
const { cleanBuildDirectory } = require('./utils/cleanBuildDirectory');
|
|
29
|
+
|
|
30
|
+
Promise.resolve().then(() => {
|
|
31
|
+
const buildFolder = path.relative(process.cwd(), paths.appBuild);
|
|
32
|
+
console.log(`Cleaning build directory at ${chalk.blue(buildFolder)}`);
|
|
33
|
+
cleanBuildDirectory();
|
|
34
|
+
});
|
package/scripts/init.js
CHANGED
|
@@ -312,13 +312,13 @@ module.exports = function (
|
|
|
312
312
|
);
|
|
313
313
|
}
|
|
314
314
|
|
|
315
|
-
// Install react and
|
|
316
|
-
// which doesn't install react and
|
|
315
|
+
// Install react and @reactunity/renderer for backward compatibility with old CRA cli
|
|
316
|
+
// which doesn't install react and @reactunity/renderer along with react-unity-scripts
|
|
317
317
|
if (!isReactInstalled(appPackage)) {
|
|
318
|
-
args = args.concat(['react', '
|
|
318
|
+
args = args.concat(['react', '@reactunity/renderer']);
|
|
319
319
|
}
|
|
320
320
|
|
|
321
|
-
// Install template dependencies, and react and
|
|
321
|
+
// Install template dependencies, and react and @reactunity/renderer if missing.
|
|
322
322
|
if ((!isReactInstalled(appPackage) || templateName) && args.length > 1) {
|
|
323
323
|
console.log();
|
|
324
324
|
console.log(`Installing template dependencies using ${command}...`);
|
|
@@ -412,6 +412,6 @@ function isReactInstalled(appPackage) {
|
|
|
412
412
|
|
|
413
413
|
return (
|
|
414
414
|
typeof dependencies.react !== 'undefined' &&
|
|
415
|
-
typeof dependencies['
|
|
415
|
+
typeof dependencies['@reactunity/renderer'] !== 'undefined'
|
|
416
416
|
);
|
|
417
417
|
}
|
package/scripts/start.js
CHANGED
|
@@ -47,7 +47,6 @@ const paths = require('../config/paths');
|
|
|
47
47
|
const configFactory = require('../config/webpack.config');
|
|
48
48
|
const createDevServerConfig = require('../config/webpackDevServer.config');
|
|
49
49
|
const getClientEnvironment = require('../config/env');
|
|
50
|
-
const react = require(require.resolve('react', { paths: [paths.appPath] }));
|
|
51
50
|
|
|
52
51
|
const env = getClientEnvironment(paths.publicUrlOrPath.slice(0, -1));
|
|
53
52
|
const useYarn = fs.existsSync(paths.yarnLockFile);
|
|
@@ -134,14 +133,6 @@ checkBrowsers(paths.appPath, isInteractive)
|
|
|
134
133
|
clearConsole();
|
|
135
134
|
}
|
|
136
135
|
|
|
137
|
-
if (env.raw.FAST_REFRESH && semver.lt(react.version, '16.10.0')) {
|
|
138
|
-
console.log(
|
|
139
|
-
chalk.yellow(
|
|
140
|
-
`Fast Refresh requires React 16.10 or higher. You are using React ${react.version}.`
|
|
141
|
-
)
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
136
|
console.log(chalk.cyan('Starting the development server...\n'));
|
|
146
137
|
});
|
|
147
138
|
|