@reactunity/scripts 0.16.3 → 0.16.5
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 +1 -0
- package/config/webpack.config.js +4 -3
- package/package.json +1 -1
- package/scripts/build.js +6 -3
- package/scripts/clean.js +1 -1
- package/scripts/utils/cleanBuildDirectory.js +36 -6
package/README.md
CHANGED
|
@@ -28,6 +28,7 @@ Environment variables of CRA can be used with React Unity. However, there are so
|
|
|
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
|
- `JSX_IMPORT_SOURCE` - Can be used to allow some custom JSX transformations. For example, set this variable to `@emotion/react` for Emotion.
|
|
31
|
+
- `ENABLE_SCOPE` - Can be used to restricts imports to `src` folder only.
|
|
31
32
|
|
|
32
33
|
Environment variables can also be defined by having `.env`, `.env.local`, `.env.<development|production>` in project folder.
|
|
33
34
|
|
package/config/webpack.config.js
CHANGED
|
@@ -57,6 +57,7 @@ const emitErrorsAsWarnings = process.env.ESLINT_NO_DEV_ERRORS === 'true';
|
|
|
57
57
|
const disableESLintPlugin = process.env.DISABLE_ESLINT_PLUGIN === 'true';
|
|
58
58
|
const extractCss = process.env.EXTRACT_CSS === 'true';
|
|
59
59
|
const generateManifest = process.env.GENERATE_MANIFEST !== 'false';
|
|
60
|
+
const enableScope = process.env.ENABLE_SCOPE === 'true';
|
|
60
61
|
|
|
61
62
|
const imageInlineSizeLimit = parseInt(
|
|
62
63
|
process.env.IMAGE_INLINE_SIZE_LIMIT || '0'
|
|
@@ -333,7 +334,7 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
333
334
|
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
|
|
334
335
|
// please link the files into your node_modules/ and let module-resolution kick in.
|
|
335
336
|
// Make sure your source files are compiled, as they will not be processed in any way.
|
|
336
|
-
new ModuleScopePlugin(paths.appSrc, [
|
|
337
|
+
enableScope && new ModuleScopePlugin(paths.appSrc, [
|
|
337
338
|
paths.appPackageJson,
|
|
338
339
|
reactRefreshRuntimeEntry,
|
|
339
340
|
reactRefreshWebpackPluginRuntimeEntry,
|
|
@@ -341,7 +342,7 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
341
342
|
babelRuntimeEntryHelpers,
|
|
342
343
|
babelRuntimeRegenerator,
|
|
343
344
|
]),
|
|
344
|
-
],
|
|
345
|
+
].filter(Boolean),
|
|
345
346
|
},
|
|
346
347
|
module: {
|
|
347
348
|
strictExportPresence: true,
|
|
@@ -400,7 +401,7 @@ const baseConfigFactory = function (webpackEnv) {
|
|
|
400
401
|
// The preset includes JSX, Flow, TypeScript, and some ESnext features.
|
|
401
402
|
{
|
|
402
403
|
test: /\.(js|mjs|jsx|ts|tsx)$/,
|
|
403
|
-
include: paths.
|
|
404
|
+
include: paths.appPath,
|
|
404
405
|
loader: require.resolve('babel-loader'),
|
|
405
406
|
options: {
|
|
406
407
|
customize: require.resolve(
|
package/package.json
CHANGED
package/scripts/build.js
CHANGED
|
@@ -33,7 +33,7 @@ const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
|
|
|
33
33
|
const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages');
|
|
34
34
|
const FileSizeReporter = require('react-dev-utils/FileSizeReporter');
|
|
35
35
|
const printBuildError = require('react-dev-utils/printBuildError');
|
|
36
|
-
const { cleanBuildDirectory } = require('./utils/cleanBuildDirectory');
|
|
36
|
+
const { cleanBuildDirectory, cleanUnusedMetaFiles } = require('./utils/cleanBuildDirectory');
|
|
37
37
|
|
|
38
38
|
const measureFileSizesBeforeBuild =
|
|
39
39
|
FileSizeReporter.measureFileSizesBeforeBuild;
|
|
@@ -66,11 +66,14 @@ checkBrowsers(paths.appPath, isInteractive)
|
|
|
66
66
|
return measureFileSizesBeforeBuild(paths.appBuild);
|
|
67
67
|
})
|
|
68
68
|
.then(previousFileSizes => {
|
|
69
|
-
cleanBuildDirectory();
|
|
69
|
+
const metaFiles = cleanBuildDirectory(false);
|
|
70
70
|
// Merge with the public folder
|
|
71
71
|
copyPublicFolder();
|
|
72
72
|
// Start the webpack build
|
|
73
|
-
return build(previousFileSizes)
|
|
73
|
+
return build(previousFileSizes).then((res) => {
|
|
74
|
+
cleanUnusedMetaFiles(metaFiles);
|
|
75
|
+
return res;
|
|
76
|
+
});
|
|
74
77
|
})
|
|
75
78
|
.then(
|
|
76
79
|
({ stats, previousFileSizes, warnings }) => {
|
package/scripts/clean.js
CHANGED
|
@@ -30,5 +30,5 @@ const { cleanBuildDirectory } = require('./utils/cleanBuildDirectory');
|
|
|
30
30
|
Promise.resolve().then(() => {
|
|
31
31
|
const buildFolder = path.relative(process.cwd(), paths.appBuild);
|
|
32
32
|
console.log(`Cleaning build directory at ${chalk.blue(buildFolder)}`);
|
|
33
|
-
cleanBuildDirectory();
|
|
33
|
+
cleanBuildDirectory(true);
|
|
34
34
|
});
|
|
@@ -12,7 +12,7 @@ const path = require('path');
|
|
|
12
12
|
const fs = require('fs-extra');
|
|
13
13
|
const paths = require('../../config/paths');
|
|
14
14
|
|
|
15
|
-
function cleanBuildDirectory() {
|
|
15
|
+
function cleanBuildDirectory(cleanMetaFiles = false) {
|
|
16
16
|
try {
|
|
17
17
|
if (fs.existsSync(paths.appManifest)) {
|
|
18
18
|
// Clean only the files inside the asset-manifest so that we avoid cleaning files belonging to user
|
|
@@ -21,26 +21,55 @@ function cleanBuildDirectory() {
|
|
|
21
21
|
|
|
22
22
|
const keys = Object.keys(manifest.files);
|
|
23
23
|
|
|
24
|
+
const metaFiles = [];
|
|
25
|
+
|
|
24
26
|
for (const key of keys) {
|
|
25
27
|
const file = manifest.files[key];
|
|
26
28
|
const filePath = path.join(paths.appBuild, file);
|
|
27
29
|
const metaFile = filePath + '.meta';
|
|
28
30
|
|
|
29
31
|
fs.removeSync(filePath);
|
|
30
|
-
|
|
32
|
+
|
|
33
|
+
if (fs.existsSync(metaFile)) {
|
|
34
|
+
if (cleanMetaFiles) fs.removeSync(metaFile);
|
|
35
|
+
else metaFiles.push(metaFile);
|
|
36
|
+
}
|
|
31
37
|
}
|
|
32
38
|
|
|
33
39
|
const manifestMeta = paths.appManifest + '.meta';
|
|
34
40
|
fs.removeSync(paths.appManifest);
|
|
35
|
-
|
|
41
|
+
|
|
42
|
+
if (fs.existsSync(manifestMeta)) {
|
|
43
|
+
if (cleanMetaFiles) fs.removeSync(manifestMeta);
|
|
44
|
+
else metaFiles.push(manifestMeta);
|
|
45
|
+
}
|
|
36
46
|
|
|
37
47
|
cleanEmptyFoldersRecursively(null, paths.appBuild, true);
|
|
38
48
|
|
|
39
|
-
return;
|
|
49
|
+
return metaFiles;
|
|
40
50
|
}
|
|
41
|
-
} catch (err) {
|
|
51
|
+
} catch (err) {
|
|
52
|
+
console.log('Skipped clearing output directory because asset manifest was not found. Please clean the output directory manually if necessary.');
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
42
56
|
|
|
43
|
-
|
|
57
|
+
function cleanUnusedMetaFiles(metaFiles) {
|
|
58
|
+
try {
|
|
59
|
+
for (const metaFile of metaFiles) {
|
|
60
|
+
try {
|
|
61
|
+
if (!fs.existsSync(metaFile)) continue;
|
|
62
|
+
|
|
63
|
+
const nonMetaFile = metaFile.replace(/\.meta$/, '');
|
|
64
|
+
if (fs.existsSync(nonMetaFile)) continue;
|
|
65
|
+
|
|
66
|
+
fs.removeSync(metaFile);
|
|
67
|
+
} catch (err) {
|
|
68
|
+
console.log('Error while cleaning meta file: ' + metaFile);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
} catch (err) {
|
|
72
|
+
}
|
|
44
73
|
}
|
|
45
74
|
|
|
46
75
|
|
|
@@ -74,3 +103,4 @@ function cleanEmptyFoldersRecursively(parent, folder, skipFirst) {
|
|
|
74
103
|
}
|
|
75
104
|
|
|
76
105
|
module.exports.cleanBuildDirectory = cleanBuildDirectory;
|
|
106
|
+
module.exports.cleanUnusedMetaFiles = cleanUnusedMetaFiles;
|