@reactunity/scripts 0.10.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 +5 -1
- package/bin/react-unity-scripts.js +2 -1
- package/config/paths.js +7 -0
- package/config/public/index.html +2 -2
- package/config/webpack.config.js +20 -4
- package/config/webpackDevServer.config.js +7 -0
- package/package.json +15 -15
- package/scripts/build.js +3 -15
- package/scripts/clean.js +34 -0
- package/scripts/utils/cleanBuildDirectory.js +76 -0
package/README.md
CHANGED
|
@@ -32,8 +32,12 @@ Environment variables can also be defined by having `.env`, `.env.local`, `.env.
|
|
|
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
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/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'),
|
|
@@ -89,7 +92,9 @@ module.exports = {
|
|
|
89
92
|
dotenv: resolveApp('.env'),
|
|
90
93
|
appPath: resolveApp('.'),
|
|
91
94
|
appBuild: resolveApp(buildPath),
|
|
95
|
+
appManifest: resolveApp(manifestPath),
|
|
92
96
|
appPublic: resolveApp('public'),
|
|
97
|
+
appPublicAlt: resolveApp('previewer'),
|
|
93
98
|
appHtml: resolveApp('public/index.html'),
|
|
94
99
|
appIndexJs: resolveModule(resolveApp, 'src/index'),
|
|
95
100
|
appPackageJson: resolveApp('package.json'),
|
|
@@ -128,7 +133,9 @@ if (
|
|
|
128
133
|
dotenv: resolveOwn(`${templatePath}/.env`),
|
|
129
134
|
appPath: resolveApp('.'),
|
|
130
135
|
appBuild: resolveOwn(path.join('../..', buildPath)),
|
|
136
|
+
appManifest: resolveOwn(path.join('../..', manifestPath)),
|
|
131
137
|
appPublic: resolveOwn(`${templatePath}/public`),
|
|
138
|
+
appPreviewer: resolveOwn(`${templatePath}/previewer`),
|
|
132
139
|
appHtml: resolveOwn(`${templatePath}/public/index.html`),
|
|
133
140
|
appIndexJs: resolveModule(resolveOwn, `${templatePath}/src/index`),
|
|
134
141
|
appPackageJson: resolveOwn('package.json'),
|
package/config/public/index.html
CHANGED
|
@@ -65,8 +65,8 @@
|
|
|
65
65
|
<code>Type</code> property must be set to <code>Url</code> and <code>Source Path</code> property must be set to
|
|
66
66
|
<code>/index.js</code>.
|
|
67
67
|
|
|
68
|
-
After building, you must copy the built directory to <code>
|
|
69
|
-
that there is a <code>
|
|
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
70
|
</p>
|
|
71
71
|
</main>
|
|
72
72
|
|
package/config/webpack.config.js
CHANGED
|
@@ -94,6 +94,19 @@ const cssModuleRegex = /\.module\.css$/;
|
|
|
94
94
|
const sassRegex = /\.(scss|sass)$/;
|
|
95
95
|
const sassModuleRegex = /\.module\.(scss|sass)$/;
|
|
96
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
|
+
|
|
97
110
|
// This is the production and development configuration.
|
|
98
111
|
// It is focused on developer experience, fast rebuilds, and a minimal bundle.
|
|
99
112
|
const baseConfigFactory = function (webpackEnv) {
|
|
@@ -184,15 +197,18 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
184
197
|
: isEnvDevelopment && (sourceMapType || 'eval-source-map'),
|
|
185
198
|
// These are the "entry points" to our application.
|
|
186
199
|
// This means they will be the "root" imports that are included in JS bundle.
|
|
187
|
-
entry:
|
|
200
|
+
entry: {
|
|
201
|
+
index: paths.appIndexJs,
|
|
202
|
+
...entryObj,
|
|
203
|
+
},
|
|
188
204
|
output: {
|
|
189
205
|
// The build folder.
|
|
190
206
|
path: paths.appBuild,
|
|
191
207
|
// Add /* filename */ comments to generated require()s in the output.
|
|
192
208
|
pathinfo: isEnvDevelopment,
|
|
193
|
-
// There
|
|
209
|
+
// There can be multiple entry bundles, and one file per asynchronous chunk.
|
|
194
210
|
// In development, it does not produce real files.
|
|
195
|
-
filename: isEnvDevelopment ? '
|
|
211
|
+
filename: isEnvDevelopment ? '[name].js' : process.env.FILENAME || '[name].js',
|
|
196
212
|
// There are also additional JS chunk files if you use code splitting.
|
|
197
213
|
chunkFilename: isEnvProduction
|
|
198
214
|
? 'static/js/[name].chunk.js'
|
|
@@ -590,7 +606,7 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
590
606
|
manifest[file.name] = file.path;
|
|
591
607
|
return manifest;
|
|
592
608
|
}, seed);
|
|
593
|
-
const entrypointFiles = entrypoints.
|
|
609
|
+
const entrypointFiles = entrypoints.index.filter(
|
|
594
610
|
fileName => !fileName.endsWith('.map')
|
|
595
611
|
);
|
|
596
612
|
|
|
@@ -90,6 +90,13 @@ module.exports = function (proxy, allowedHost) {
|
|
|
90
90
|
},
|
|
91
91
|
},
|
|
92
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
|
+
|
|
93
100
|
// If installed, serve the ReactUnity Web Previewer
|
|
94
101
|
...servePreviewerIfExists(),
|
|
95
102
|
|
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,14 +44,14 @@
|
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@babel/core": "^7.17.
|
|
47
|
+
"@babel/core": "^7.17.10",
|
|
48
48
|
"@babel/eslint-parser": "^7.17.0",
|
|
49
49
|
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.5",
|
|
50
|
-
"@types/react": "^18.0.
|
|
50
|
+
"@types/react": "^18.0.9",
|
|
51
51
|
"@types/webpack-env": "^1.16.4",
|
|
52
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
53
|
-
"@typescript-eslint/parser": "^5.
|
|
54
|
-
"babel-jest": "^28.0
|
|
52
|
+
"@typescript-eslint/eslint-plugin": "^5.22.0",
|
|
53
|
+
"@typescript-eslint/parser": "^5.22.0",
|
|
54
|
+
"babel-jest": "^28.1.0",
|
|
55
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",
|
|
@@ -62,22 +62,22 @@
|
|
|
62
62
|
"css-loader": "^6.7.1",
|
|
63
63
|
"dotenv": "^16.0.0",
|
|
64
64
|
"dotenv-expand": "^8.0.3",
|
|
65
|
-
"eslint": "^8.
|
|
65
|
+
"eslint": "^8.15.0",
|
|
66
66
|
"eslint-plugin-import": "^2.26.0",
|
|
67
67
|
"eslint-plugin-jest": "^26.1.5",
|
|
68
68
|
"eslint-plugin-react": "^7.29.4",
|
|
69
69
|
"eslint-plugin-react-hooks": "^4.5.0",
|
|
70
|
-
"eslint-plugin-testing-library": "^5.
|
|
70
|
+
"eslint-plugin-testing-library": "^5.4.0",
|
|
71
71
|
"eslint-webpack-plugin": "^3.1.1",
|
|
72
72
|
"file-loader": "^6.2.0",
|
|
73
73
|
"fs-extra": "^10.1.0",
|
|
74
74
|
"identity-obj-proxy": "^3.0.0",
|
|
75
|
-
"jest": "^28.0
|
|
76
|
-
"jest-resolve": "^28.0
|
|
75
|
+
"jest": "^28.1.0",
|
|
76
|
+
"jest-resolve": "^28.1.0",
|
|
77
77
|
"jest-watch-typeahead": "^1.1.0",
|
|
78
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",
|
|
@@ -95,20 +95,20 @@
|
|
|
95
95
|
"terser-webpack-plugin": "^5.3.1",
|
|
96
96
|
"url-loader": "^4.1.1",
|
|
97
97
|
"webpack": "^5.72.0",
|
|
98
|
-
"webpack-dev-server": "^4.
|
|
98
|
+
"webpack-dev-server": "^4.9.0",
|
|
99
99
|
"webpack-manifest-plugin": "^5.0.0"
|
|
100
100
|
},
|
|
101
101
|
"devDependencies": {
|
|
102
|
-
"typescript": "^4.6.
|
|
102
|
+
"typescript": "^4.6.4"
|
|
103
103
|
},
|
|
104
104
|
"optionalDependencies": {
|
|
105
105
|
"fsevents": "^2.3.2"
|
|
106
106
|
},
|
|
107
107
|
"peerDependencies": {
|
|
108
108
|
"@reactunity/previewer": "*",
|
|
109
|
-
"@reactunity/renderer": "^0.
|
|
109
|
+
"@reactunity/renderer": "^0.11.0",
|
|
110
110
|
"react": "^18.0.0",
|
|
111
|
-
"typescript": "^4.6.
|
|
111
|
+
"typescript": "^4.6.4"
|
|
112
112
|
},
|
|
113
113
|
"peerDependenciesMeta": {
|
|
114
114
|
"@reactunity/previewer": {
|
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
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
const path = require('path');
|
|
12
|
+
const fs = require('fs-extra');
|
|
13
|
+
const paths = require('../../config/paths');
|
|
14
|
+
|
|
15
|
+
function cleanBuildDirectory() {
|
|
16
|
+
try {
|
|
17
|
+
if (fs.existsSync(paths.appManifest)) {
|
|
18
|
+
// Clean only the files inside the asset-manifest so that we avoid cleaning files belonging to user
|
|
19
|
+
const manifestContent = fs.readFileSync(paths.appManifest, 'utf8');
|
|
20
|
+
const manifest = JSON.parse(manifestContent);
|
|
21
|
+
|
|
22
|
+
const keys = Object.keys(manifest.files);
|
|
23
|
+
|
|
24
|
+
for (const key of keys) {
|
|
25
|
+
const file = manifest.files[key];
|
|
26
|
+
const filePath = path.join(paths.appBuild, file);
|
|
27
|
+
const metaFile = filePath + '.meta';
|
|
28
|
+
|
|
29
|
+
fs.removeSync(filePath);
|
|
30
|
+
fs.removeSync(metaFile);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const manifestMeta = paths.appManifest + '.meta';
|
|
34
|
+
fs.removeSync(paths.appManifest);
|
|
35
|
+
fs.removeSync(manifestMeta);
|
|
36
|
+
|
|
37
|
+
cleanEmptyFoldersRecursively(null, paths.appBuild, true);
|
|
38
|
+
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
} catch (err) { }
|
|
42
|
+
|
|
43
|
+
console.log('Skipped clearing output directory because asset manifest was not found. Please clean the output directory manually if necessary.');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
function cleanEmptyFoldersRecursively(parent, folder, skipFirst) {
|
|
48
|
+
if (!fs.existsSync(folder)) return;
|
|
49
|
+
var isDir = fs.statSync(folder).isDirectory();
|
|
50
|
+
if (!isDir) return;
|
|
51
|
+
|
|
52
|
+
var files = fs.readdirSync(folder);
|
|
53
|
+
if (files.length > 0) {
|
|
54
|
+
files.forEach(function (file) {
|
|
55
|
+
var fullPath = path.join(folder, file);
|
|
56
|
+
cleanEmptyFoldersRecursively(folder, fullPath, false);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// re-evaluate files; after deleting subfolder
|
|
60
|
+
// we may have parent folder empty now
|
|
61
|
+
files = fs.readdirSync(folder);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (!skipFirst && files.length == 0) {
|
|
65
|
+
fs.rmdirSync(folder);
|
|
66
|
+
|
|
67
|
+
if (parent) {
|
|
68
|
+
const folderName = path.basename(folder);
|
|
69
|
+
const dirMeta = path.join(parent, folderName + '.meta');
|
|
70
|
+
fs.removeSync(dirMeta);
|
|
71
|
+
}
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
module.exports.cleanBuildDirectory = cleanBuildDirectory;
|