@reactunity/scripts 0.9.1 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -25,7 +25,7 @@ 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
- - `FASH_REFRESH` - This experimental feature can be turned on. `false` by default.
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.
@@ -34,6 +34,6 @@ Custom environment variables are also possible as in [CRA](https://create-react-
34
34
 
35
35
  ## WebGL Inspector
36
36
 
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 prebuilt Unity application that renders your React code. This application can be used to quickly test the React code without even launching Unity. It also reacts to the changes in code by utilizing HMR.
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 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
38
 
39
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 `public` folder under your React project.
package/config/env.js CHANGED
@@ -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 === 'true' || false,
98
+ FAST_REFRESH: process.env.FAST_REFRESH !== 'false',
99
99
  }
100
100
  );
101
101
  // Stringify all values so we can feed into webpack DefinePlugin
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>public</code> folder inside your React project, so
69
+ that there is a <code>public/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>
@@ -74,6 +74,20 @@ 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$/;
@@ -127,7 +141,13 @@ const baseConfigFactory = function (webpackEnv) {
127
141
  // https://github.com/facebook/create-react-app/issues/2677
128
142
  ident: 'postcss',
129
143
  config: false,
130
- plugins: ['tailwindcss'],
144
+ plugins: {
145
+ ...usePostcssPluginIfExists('postcss-import'),
146
+ 'tailwindcss': {},
147
+ ...usePostcssPluginIfExists('postcss-nesting'),
148
+ ...usePostcssPluginIfExists('postcss-custom-properties'),
149
+ ...usePostcssPluginIfExists('postcss-css-variables'),
150
+ },
131
151
  },
132
152
  sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
133
153
  },
@@ -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,12 @@ module.exports = function (proxy, allowedHost) {
82
89
  ignored: ignoredFiles(paths.appSrc),
83
90
  },
84
91
  },
92
+
93
+ // If installed, serve the ReactUnity Web Previewer
94
+ ...servePreviewerIfExists(),
95
+
96
+ // Serve the fallback of web previewer as the index page
97
+ { directory: path.join(__dirname, 'public'), },
85
98
  ],
86
99
 
87
100
  client: {
@@ -93,10 +106,7 @@ module.exports = function (proxy, allowedHost) {
93
106
  pathname: sockPath,
94
107
  port: sockPort,
95
108
  },
96
- overlay: {
97
- errors: true,
98
- warnings: false,
99
- },
109
+ overlay: false,
100
110
  },
101
111
  devMiddleware: {
102
112
  // 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.9.1",
3
+ "version": "0.10.0",
4
4
  "description": "Configuration and scripts for React Unity.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -44,82 +44,78 @@
44
44
  }
45
45
  },
46
46
  "dependencies": {
47
- "@babel/core": "^7.17.0",
47
+ "@babel/core": "^7.17.9",
48
48
  "@babel/eslint-parser": "^7.17.0",
49
- "@pmmmwh/react-refresh-webpack-plugin": "^0.5.4",
50
- "@types/react": "^17.0.39",
51
- "@types/webpack-env": "^1.16.3",
52
- "@typescript-eslint/eslint-plugin": "^5.10.2",
53
- "@typescript-eslint/parser": "^5.10.2",
54
- "babel-jest": "^27.5.0",
55
- "babel-loader": "^8.2.3",
49
+ "@pmmmwh/react-refresh-webpack-plugin": "^0.5.5",
50
+ "@types/react": "^18.0.8",
51
+ "@types/webpack-env": "^1.16.4",
52
+ "@typescript-eslint/eslint-plugin": "^5.21.0",
53
+ "@typescript-eslint/parser": "^5.21.0",
54
+ "babel-jest": "^28.0.2",
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.6.0",
62
+ "css-loader": "^6.7.1",
63
63
  "dotenv": "^16.0.0",
64
- "dotenv-expand": "^8.0.1",
65
- "eslint": "^8.8.0",
66
- "eslint-plugin-import": "^2.25.4",
67
- "eslint-plugin-jest": "^26.0.0",
68
- "eslint-plugin-react": "^7.28.0",
69
- "eslint-plugin-react-hooks": "^4.3.0",
70
- "eslint-plugin-testing-library": "^5.0.5",
64
+ "dotenv-expand": "^8.0.3",
65
+ "eslint": "^8.14.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.3.1",
71
71
  "eslint-webpack-plugin": "^3.1.1",
72
72
  "file-loader": "^6.2.0",
73
- "fs-extra": "^10.0.0",
73
+ "fs-extra": "^10.1.0",
74
74
  "identity-obj-proxy": "^3.0.0",
75
- "jest": "^27.5.0",
76
- "jest-resolve": "^27.5.0",
77
- "jest-watch-typeahead": "^1.0.0",
78
- "mini-css-extract-plugin": "^2.5.3",
75
+ "jest": "^28.0.2",
76
+ "jest-resolve": "^28.0.2",
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.6",
80
+ "postcss": "^8.4.12",
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.0",
86
- "react-refresh": "^0.11.0",
85
+ "react-dev-utils": "^12.0.1",
86
+ "react-refresh": "^0.13.0",
87
87
  "resolve": "^1.22.0",
88
88
  "resolve-url-loader": "^5.0.0",
89
- "sass": "^1.49.7",
90
- "sass-loader": "^12.4.0",
91
- "semver": "^7.3.5",
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.18",
94
+ "tailwindcss": "^3.0.24",
95
95
  "terser-webpack-plugin": "^5.3.1",
96
96
  "url-loader": "^4.1.1",
97
- "webpack": "^5.68.0",
98
- "webpack-dev-server": "^4.7.4",
99
- "webpack-manifest-plugin": "^4.1.1"
97
+ "webpack": "^5.72.0",
98
+ "webpack-dev-server": "^4.8.1",
99
+ "webpack-manifest-plugin": "^5.0.0"
100
100
  },
101
101
  "devDependencies": {
102
- "typescript": "^4.5.5"
102
+ "typescript": "^4.6.3"
103
103
  },
104
104
  "optionalDependencies": {
105
105
  "fsevents": "^2.3.2"
106
106
  },
107
107
  "peerDependencies": {
108
- "@reactunity/renderer": "^0.9.0",
109
- "react": ">= 16",
110
- "typescript": "^4.5.5"
108
+ "@reactunity/previewer": "*",
109
+ "@reactunity/renderer": "^0.10.0",
110
+ "react": "^18.0.0",
111
+ "typescript": "^4.6.3"
111
112
  },
112
113
  "peerDependenciesMeta": {
114
+ "@reactunity/previewer": {
115
+ "optional": true
116
+ },
113
117
  "typescript": {
114
118
  "optional": true
115
119
  }
116
- },
117
- "bundledDependencies": [
118
- "@typescript-eslint/eslint-plugin",
119
- "eslint-plugin-import",
120
- "eslint-plugin-jest",
121
- "eslint-plugin-react",
122
- "eslint-plugin-react-hooks",
123
- "eslint-plugin-testing-library"
124
- ]
120
+ }
125
121
  }