Skip to content

Commit 689862e

Browse files
committed
add ENABLE_SCOPE option
1 parent 70dda23 commit 689862e

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Environment variables of CRA can be used with React Unity. However, there are so
2828
- `FAST_REFRESH` - This can be set to `false` to disable `react-refresh` if you are having problems with hot reload
2929
- `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.
3030
- `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.
3132

3233
Environment variables can also be defined by having `.env`, `.env.local`, `.env.<development|production>` in project folder.
3334

config/webpack.config.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const emitErrorsAsWarnings = process.env.ESLINT_NO_DEV_ERRORS === 'true';
5757
const disableESLintPlugin = process.env.DISABLE_ESLINT_PLUGIN === 'true';
5858
const extractCss = process.env.EXTRACT_CSS === 'true';
5959
const generateManifest = process.env.GENERATE_MANIFEST !== 'false';
60+
const enableScope = process.env.ENABLE_SCOPE === 'true';
6061

6162
const imageInlineSizeLimit = parseInt(
6263
process.env.IMAGE_INLINE_SIZE_LIMIT || '0'
@@ -333,15 +334,15 @@ const baseConfigFactory = function (webpackEnv) {
333334
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
334335
// please link the files into your node_modules/ and let module-resolution kick in.
335336
// 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, [
337338
paths.appPackageJson,
338339
reactRefreshRuntimeEntry,
339340
reactRefreshWebpackPluginRuntimeEntry,
340341
babelRuntimeEntry,
341342
babelRuntimeEntryHelpers,
342343
babelRuntimeRegenerator,
343344
]),
344-
],
345+
].filter(Boolean),
345346
},
346347
module: {
347348
strictExportPresence: true,
@@ -400,7 +401,7 @@ const baseConfigFactory = function (webpackEnv) {
400401
// The preset includes JSX, Flow, TypeScript, and some ESnext features.
401402
{
402403
test: /\.(js|mjs|jsx|ts|tsx)$/,
403-
include: paths.appSrc,
404+
include: paths.appPath,
404405
loader: require.resolve('babel-loader'),
405406
options: {
406407
customize: require.resolve(

0 commit comments

Comments
 (0)