@nx/react-native 18.0.0-beta.1 → 18.0.0-canary.20240201-8762c38
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/.eslintrc.json +6 -1
- package/executors.json +5 -0
- package/generators.json +10 -9
- package/migrations.json +73 -1
- package/package.json +10 -15
- package/plugins/metro-resolver.js +4 -1
- package/plugins/with-nx-metro.js +6 -2
- package/src/executors/build-android/build-android.impl.js +1 -5
- package/src/executors/build-android/build-android.impl.ts +1 -5
- package/src/executors/bundle/schema.d.ts +1 -1
- package/src/executors/ensure-symlink/ensure-symlink.impl.d.ts +4 -0
- package/src/executors/ensure-symlink/ensure-symlink.impl.js +4 -0
- package/src/executors/ensure-symlink/ensure-symlink.impl.ts +4 -0
- package/src/executors/run-android/run-android.impl.js +4 -16
- package/src/executors/run-android/run-android.impl.ts +8 -17
- package/src/executors/run-ios/run-ios.impl.js +4 -16
- package/src/executors/run-ios/run-ios.impl.ts +9 -18
- package/src/executors/start/schema.d.ts +1 -1
- package/src/executors/start/start.impl.js +11 -26
- package/src/executors/start/start.impl.ts +14 -28
- package/src/executors/storybook/storybook.impl.d.ts +4 -0
- package/src/executors/storybook/storybook.impl.js +5 -1
- package/src/executors/storybook/storybook.impl.ts +13 -15
- package/src/executors/sync-deps/sync-deps.impl.d.ts +2 -2
- package/src/executors/sync-deps/sync-deps.impl.js +20 -5
- package/src/executors/sync-deps/sync-deps.impl.ts +20 -9
- package/src/executors/upgrade/schema.d.ts +1 -0
- package/src/executors/upgrade/schema.json +11 -0
- package/src/executors/upgrade/upgrade.impl.d.ts +13 -0
- package/src/executors/upgrade/upgrade.impl.js +47 -0
- package/src/executors/upgrade/upgrade.impl.ts +64 -0
- package/src/generators/application/application.js +21 -7
- package/src/generators/application/application.spec.ts +27 -0
- package/src/generators/application/files/app/.babelrc.js.template +23 -0
- package/src/generators/application/files/app/android/app/build.gradle.template +12 -28
- package/src/generators/application/files/app/android/app/src/debug/AndroidManifest.xml.template +2 -6
- package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainActivity.kt.template +22 -0
- package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainApplication.kt.template +45 -0
- package/src/generators/application/files/app/android/build.gradle.template +7 -20
- package/src/generators/application/files/app/android/gradle/wrapper/gradle-wrapper.properties +2 -1
- package/src/generators/application/files/app/android/gradle.properties +0 -3
- package/src/generators/application/files/app/android/gradlew.template +12 -7
- package/src/generators/application/files/app/android/settings.gradle.template +2 -2
- package/src/generators/application/files/app/ios/Podfile.template +0 -7
- package/src/generators/application/files/app/ios/__className__/AppDelegate.mm.template +5 -0
- package/src/generators/application/files/app/ios/__className__/Info.plist.template +5 -8
- package/src/generators/application/files/app/ios/__className__.xcodeproj/project.pbxproj.template +11 -33
- package/src/generators/application/files/app/metro.config.js.template +0 -4
- package/src/generators/application/files/app/src/app/App.tsx.template +5 -2
- package/src/generators/application/lib/add-e2e.d.ts +3 -0
- package/src/generators/application/lib/add-e2e.js +47 -0
- package/src/generators/application/lib/add-project.js +13 -17
- package/src/generators/application/lib/normalize-options.d.ts +4 -0
- package/src/generators/application/lib/normalize-options.js +8 -3
- package/src/generators/application/lib/normalize-options.spec.ts +48 -5
- package/src/generators/application/schema.d.ts +4 -3
- package/src/generators/application/schema.json +13 -5
- package/src/generators/component-story/component-story.d.ts +5 -8
- package/src/generators/component-story/component-story.js +8 -69
- package/src/generators/component-story/schema.d.ts +1 -0
- package/src/generators/component-story/schema.json +10 -2
- package/src/generators/init/init.js +0 -3
- package/src/generators/library/files/lib/.babelrc.js.template +21 -0
- package/src/generators/library/library.spec.ts +11 -0
- package/src/generators/library/schema.json +1 -1
- package/src/generators/stories/schema.d.ts +2 -0
- package/src/generators/stories/schema.json +14 -1
- package/src/generators/stories/stories.d.ts +5 -2
- package/src/generators/stories/stories.js +7 -50
- package/src/generators/storybook-configuration/configuration.d.ts +6 -2
- package/src/generators/storybook-configuration/configuration.js +7 -48
- package/src/generators/storybook-configuration/schema.d.ts +3 -2
- package/src/generators/storybook-configuration/schema.json +21 -11
- package/src/generators/upgrade-native/lib/normalize-options.d.ts +1 -1
- package/src/generators/upgrade-native/schema.d.ts +1 -1
- package/src/generators/upgrade-native/schema.json +2 -2
- package/src/generators/upgrade-native/upgrade-native.d.ts +2 -0
- package/src/generators/upgrade-native/upgrade-native.js +3 -0
- package/src/generators/web-configuration/files/base-vite/.babelrc.js.template +23 -0
- package/src/generators/web-configuration/files/base-vite/index.html__tmpl__ +15 -0
- package/src/generators/web-configuration/files/base-vite/public/favicon.ico +0 -0
- package/src/generators/web-configuration/files/base-vite/src/assets/.gitkeep +0 -0
- package/src/generators/web-configuration/files/base-vite/src/main-web.tsx__tmpl__ +9 -0
- package/src/generators/web-configuration/files/base-vite/vite.config.ts__tmpl__ +82 -0
- package/src/generators/web-configuration/files/base-webpack/.babelrc.js.template +23 -0
- package/src/generators/web-configuration/files/base-webpack/src/assets/.gitkeep +0 -0
- package/src/generators/web-configuration/files/base-webpack/src/favicon.ico +0 -0
- package/src/generators/web-configuration/files/base-webpack/src/index.html__tmpl__ +14 -0
- package/src/generators/web-configuration/files/base-webpack/src/main-web.tsx__tmpl__ +9 -0
- package/src/generators/web-configuration/files/base-webpack/webpack.config.js__tmpl__ +77 -0
- package/src/generators/web-configuration/lib/normalize-schema.d.ts +17 -0
- package/src/generators/web-configuration/lib/normalize-schema.js +16 -0
- package/src/generators/web-configuration/lib/webpack-targets.d.ts +7 -0
- package/src/generators/web-configuration/lib/webpack-targets.js +75 -0
- package/src/generators/web-configuration/schema.d.ts +6 -0
- package/src/generators/web-configuration/schema.json +42 -0
- package/src/generators/web-configuration/web-configuration.d.ts +12 -0
- package/src/generators/web-configuration/web-configuration.js +85 -0
- package/src/migrations/update-16-6-0/update-metro-config.js +0 -4
- package/src/migrations/update-16-9-0/remove-types-react-native.js +2 -9
- package/src/migrations/update-18-0-0/add-upgrade-target.d.ts +6 -0
- package/src/migrations/update-18-0-0/add-upgrade-target.js +33 -0
- package/src/migrations/update-18-0-0/add-web-configuration.d.ts +8 -0
- package/src/migrations/update-18-0-0/add-web-configuration.js +33 -0
- package/src/migrations/update-18-0-0/add-web-configuration.spec.ts +39 -0
- package/src/migrations/update-18-0-0/change-storybook-targets.d.ts +5 -0
- package/src/migrations/update-18-0-0/change-storybook-targets.js +57 -0
- package/src/migrations/update-18-0-0/remove-block-list.d.ts +6 -0
- package/src/migrations/update-18-0-0/remove-block-list.js +26 -0
- package/src/migrations/update-18-0-0/remove-block-list.spec.ts +68 -0
- package/src/migrations/update-18-0-0/remove-metro.d.ts +14 -0
- package/src/migrations/update-18-0-0/remove-metro.js +29 -0
- package/src/migrations/update-18-0-0/remove-symlink-target.d.ts +6 -0
- package/src/migrations/update-18-0-0/remove-symlink-target.js +30 -0
- package/src/migrations/update-18-0-0/remove-symlink-target.spec.ts +40 -0
- package/src/utils/add-jest.js +11 -0
- package/src/utils/ensure-dependencies.js +2 -6
- package/src/utils/testing-generators.js +1 -0
- package/src/utils/versions.d.ts +9 -12
- package/src/utils/versions.js +10 -13
- package/src/generators/application/files/app/android/app/src/debug/java/com/__lowerCaseName__/ReactNativeFlipper.java.template +0 -75
- package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainActivity.java.template +0 -32
- package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainApplication.java.template +0 -62
- package/src/generators/application/files/app/android/app/src/release/java/com/__lowerCaseName__/ReactNativeFlipper.java.template +0 -20
- package/src/generators/application/files/app/babel.config.json.template +0 -10
- package/src/generators/application/lib/add-detox.d.ts +0 -3
- package/src/generators/application/lib/add-detox.js +0 -23
- package/src/generators/component-story/component-story.spec.ts +0 -427
- package/src/generators/component-story/files/__componentFileName__.stories.__fileExt__ +0 -32
- package/src/generators/library/files/lib/babel.config.json.template +0 -19
- package/src/generators/stories/stories-app.spec.ts +0 -128
- package/src/generators/stories/stories-lib.spec.ts +0 -105
- package/src/generators/storybook-configuration/configuration.spec.ts +0 -135
- package/src/generators/storybook-configuration/files/app/storybook.ts.template +0 -9
- package/src/generators/storybook-configuration/files/app/toggle-storybook.tsx.template +0 -74
- package/src/generators/storybook-configuration/files/root/story-loader.ts.template +0 -5
- package/src/generators/storybook-configuration/lib/add-resolver-main-fields-to-metro-config.d.ts +0 -6
- package/src/generators/storybook-configuration/lib/add-resolver-main-fields-to-metro-config.js +0 -25
- package/src/generators/storybook-configuration/lib/add-resolver-main-fields-to-metro-config.spec.ts +0 -161
- package/src/generators/storybook-configuration/lib/create-storybook-files.d.ts +0 -6
- package/src/generators/storybook-configuration/lib/create-storybook-files.js +0 -42
- package/src/generators/storybook-configuration/lib/replace-app-import-with-storybook-toggle.d.ts +0 -7
- package/src/generators/storybook-configuration/lib/replace-app-import-with-storybook-toggle.js +0 -29
- package/src/generators/storybook-configuration/lib/replace-app-import-with-storybook-toggle.spec.ts +0 -65
- package/src/utils/find-all-npm-dependencies.d.ts +0 -2
- package/src/utils/find-all-npm-dependencies.js +0 -25
- package/src/utils/find-all-npm-dependencies.spec.ts +0 -95
- package/src/utils/symlink-task.d.ts +0 -2
- package/src/utils/symlink-task.js +0 -18
|
@@ -6,24 +6,40 @@
|
|
|
6
6
|
"description": "Set up Storybook for a React-Native app or library.",
|
|
7
7
|
"type": "object",
|
|
8
8
|
"properties": {
|
|
9
|
-
"
|
|
9
|
+
"project": {
|
|
10
10
|
"type": "string",
|
|
11
|
-
"aliases": ["
|
|
11
|
+
"aliases": ["name", "projectName"],
|
|
12
12
|
"description": "Project for which to generate Storybook configuration.",
|
|
13
13
|
"$default": {
|
|
14
14
|
"$source": "argv",
|
|
15
15
|
"index": 0
|
|
16
16
|
},
|
|
17
17
|
"x-prompt": "For which project do you want to generate Storybook configuration?",
|
|
18
|
-
"x-dropdown": "projects"
|
|
18
|
+
"x-dropdown": "projects",
|
|
19
|
+
"x-priority": "important"
|
|
20
|
+
},
|
|
21
|
+
"interactionTests": {
|
|
22
|
+
"type": "boolean",
|
|
23
|
+
"description": "Set up Storybook interaction tests.",
|
|
24
|
+
"x-prompt": "Do you want to set up Storybook interaction tests?",
|
|
25
|
+
"x-priority": "important",
|
|
26
|
+
"alias": ["configureTestRunner"],
|
|
27
|
+
"default": true
|
|
19
28
|
},
|
|
20
29
|
"generateStories": {
|
|
21
30
|
"type": "boolean",
|
|
22
|
-
"description": "Automatically generate
|
|
31
|
+
"description": "Automatically generate `*.stories.ts` files for components declared in this project?",
|
|
23
32
|
"x-prompt": "Automatically generate *.stories.ts files for components declared in this project?",
|
|
24
33
|
"default": true,
|
|
25
34
|
"x-priority": "important"
|
|
26
35
|
},
|
|
36
|
+
"configureStaticServe": {
|
|
37
|
+
"type": "boolean",
|
|
38
|
+
"description": "Specifies whether to configure a static file server target for serving storybook. Helpful for speeding up CI build/test times.",
|
|
39
|
+
"x-prompt": "Configure a static file server for the storybook instance?",
|
|
40
|
+
"default": true,
|
|
41
|
+
"x-priority": "important"
|
|
42
|
+
},
|
|
27
43
|
"js": {
|
|
28
44
|
"type": "boolean",
|
|
29
45
|
"description": "Generate JavaScript story files rather than TypeScript story files.",
|
|
@@ -40,12 +56,6 @@
|
|
|
40
56
|
"enum": ["eslint"],
|
|
41
57
|
"default": "eslint"
|
|
42
58
|
},
|
|
43
|
-
"standaloneConfig": {
|
|
44
|
-
"description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
|
|
45
|
-
"type": "boolean",
|
|
46
|
-
"default": true,
|
|
47
|
-
"x-deprecated": "Nx only supports standaloneConfig"
|
|
48
|
-
},
|
|
49
59
|
"ignorePaths": {
|
|
50
60
|
"type": "array",
|
|
51
61
|
"description": "Paths to ignore when looking for components.",
|
|
@@ -65,5 +75,5 @@
|
|
|
65
75
|
]
|
|
66
76
|
}
|
|
67
77
|
},
|
|
68
|
-
"required": ["
|
|
78
|
+
"required": ["project"]
|
|
69
79
|
}
|
|
@@ -6,7 +6,7 @@ export interface NormalizedSchema {
|
|
|
6
6
|
lowerCaseName: string;
|
|
7
7
|
entryFile: string;
|
|
8
8
|
entryFileIos: string;
|
|
9
|
-
e2eTestRunner: 'detox' | 'none';
|
|
9
|
+
e2eTestRunner: 'cypress' | 'playwright' | 'detox' | 'none';
|
|
10
10
|
offsetFromRoot: string;
|
|
11
11
|
}
|
|
12
12
|
export declare function normalizeOptions(options: UpgradeNativeConfigureSchema, appProjectRoot: string): NormalizedSchema;
|
|
@@ -4,6 +4,6 @@ export interface UpgradeNativeConfigureSchema {
|
|
|
4
4
|
name: string;
|
|
5
5
|
displayName?: string;
|
|
6
6
|
js: boolean; // default is false
|
|
7
|
-
e2eTestRunner: 'detox' | 'none'; // default is
|
|
7
|
+
e2eTestRunner: 'cypress' | 'playwright' | 'detox' | 'none'; // default is cypress
|
|
8
8
|
install: boolean; // default is true
|
|
9
9
|
}
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"e2eTestRunner": {
|
|
28
28
|
"description": "Adds the specified e2e test runner.",
|
|
29
29
|
"type": "string",
|
|
30
|
-
"enum": ["detox", "none"],
|
|
31
|
-
"default": "
|
|
30
|
+
"enum": ["cypress", "playwright", "detox", "none"],
|
|
31
|
+
"default": "cypress"
|
|
32
32
|
},
|
|
33
33
|
"install": {
|
|
34
34
|
"type": "boolean",
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* @deprecated use `nx run @nx/react-native:upgrade` instead.
|
|
3
|
+
* TODO (@xiongemi): remove this generator for nx v19
|
|
2
4
|
* This function is a destructive command that replace React Native iOS and Android code with latest.
|
|
3
5
|
* It would replace the Android and iOS folder entirely.
|
|
4
6
|
*/
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
+
* @deprecated use `nx run @nx/react-native:upgrade` instead.
|
|
4
|
+
* TODO (@xiongemi): remove this generator for nx v19
|
|
3
5
|
* This function is a destructive command that replace React Native iOS and Android code with latest.
|
|
4
6
|
* It would replace the Android and iOS folder entirely.
|
|
5
7
|
*/
|
|
@@ -11,6 +13,7 @@ const pod_install_task_1 = require("../../utils/pod-install-task");
|
|
|
11
13
|
const chmod_android_gradle_files_1 = require("../../utils/chmod-android-gradle-files");
|
|
12
14
|
const create_native_files_1 = require("./lib/create-native-files");
|
|
13
15
|
async function reactNativeUpgradeNativeGenerator(host, schema) {
|
|
16
|
+
devkit_1.logger.warn(`Please run 'nx run @nx/react-native:upgrade ${schema.name}' instead.`);
|
|
14
17
|
const { projectType, root: appProjectRoot } = (0, devkit_1.readProjectConfiguration)(host, schema.name);
|
|
15
18
|
const iosProjectRoot = (0, devkit_1.joinPathFragments)(host.root, appProjectRoot, 'ios');
|
|
16
19
|
const androidProjectRoot = (0, devkit_1.joinPathFragments)(host.root, appProjectRoot, 'android');
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module.exports = function (api) {
|
|
2
|
+
api.cache(true);
|
|
3
|
+
|
|
4
|
+
if (
|
|
5
|
+
process.env.NX_TASK_TARGET_TARGET === 'build' ||
|
|
6
|
+
process.env.NX_TASK_TARGET_TARGET.includes('storybook')
|
|
7
|
+
) {
|
|
8
|
+
return {
|
|
9
|
+
presets: [
|
|
10
|
+
[
|
|
11
|
+
'@nx/react/babel',
|
|
12
|
+
{
|
|
13
|
+
runtime: 'automatic',
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
],
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
presets: [['module:@react-native/babel-preset', { "useTransformReactJSX": true }]],
|
|
22
|
+
};
|
|
23
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en" style="height: 100%">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<title><%= className %></title>
|
|
6
|
+
<base href="/" />
|
|
7
|
+
|
|
8
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
9
|
+
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
|
10
|
+
</head>
|
|
11
|
+
<body style="height:100%">
|
|
12
|
+
<div id="root" style="display: flex; height: 100%"></div>
|
|
13
|
+
<script type="module" src="/src/main-web.tsx"></script>
|
|
14
|
+
</body>
|
|
15
|
+
</html>
|
|
File without changes
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { defineConfig } from 'vite';
|
|
2
|
+
import react from '@vitejs/plugin-react';
|
|
3
|
+
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
|
|
4
|
+
import * as esbuild from 'esbuild';
|
|
5
|
+
import { readFileSync } from 'fs';
|
|
6
|
+
|
|
7
|
+
const extensions = [
|
|
8
|
+
'.mjs',
|
|
9
|
+
'.web.tsx',
|
|
10
|
+
'.tsx',
|
|
11
|
+
'.web.ts',
|
|
12
|
+
'.ts',
|
|
13
|
+
'.web.jsx',
|
|
14
|
+
'.jsx',
|
|
15
|
+
'.web.js',
|
|
16
|
+
'.js',
|
|
17
|
+
'.css',
|
|
18
|
+
'.json',
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
const rollupPlugin = (matchers: RegExp[]) => ({
|
|
22
|
+
name: 'js-in-jsx',
|
|
23
|
+
load(id: string) {
|
|
24
|
+
if (matchers.some((matcher) => matcher.test(id)) && id.endsWith('.js')) {
|
|
25
|
+
const file = readFileSync(id, { encoding: 'utf-8' });
|
|
26
|
+
return esbuild.transformSync(file, { loader: 'jsx', jsx: 'automatic' });
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export default defineConfig({
|
|
32
|
+
root: __dirname,
|
|
33
|
+
cacheDir: '../../node_modules/.vite/<%= fileName %>',
|
|
34
|
+
define: {
|
|
35
|
+
global: 'window',
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
resolve: {
|
|
39
|
+
extensions,
|
|
40
|
+
alias: {
|
|
41
|
+
'react-native': 'react-native-web',
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
build: {
|
|
46
|
+
reportCompressedSize: true,
|
|
47
|
+
commonjsOptions: { transformMixedEsModules: true },
|
|
48
|
+
outDir: '../../dist/apps/<%= fileName %>/web',
|
|
49
|
+
rollupOptions: {
|
|
50
|
+
plugins: [rollupPlugin([/react-native-vector-icons/])],
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
server: {
|
|
55
|
+
port: 4200,
|
|
56
|
+
host: 'localhost',
|
|
57
|
+
fs: {
|
|
58
|
+
// Allow serving files from one level up to the project root
|
|
59
|
+
allow: ['..'],
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
preview: {
|
|
64
|
+
port: 4300,
|
|
65
|
+
host: 'localhost',
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
optimizeDeps: {
|
|
69
|
+
esbuildOptions: {
|
|
70
|
+
resolveExtensions: extensions,
|
|
71
|
+
jsx: 'automatic',
|
|
72
|
+
loader: { '.js': 'jsx' },
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
plugins: [react(), nxViteTsPaths()],
|
|
77
|
+
|
|
78
|
+
// Uncomment this if you are using workers.
|
|
79
|
+
// worker: {
|
|
80
|
+
// plugins: [ nxViteTsPaths() ],
|
|
81
|
+
// },
|
|
82
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module.exports = function (api) {
|
|
2
|
+
api.cache(true);
|
|
3
|
+
|
|
4
|
+
if (
|
|
5
|
+
process.env.NX_TASK_TARGET_TARGET === 'build' ||
|
|
6
|
+
process.env.NX_TASK_TARGET_TARGET.includes('storybook')
|
|
7
|
+
) {
|
|
8
|
+
return {
|
|
9
|
+
presets: [
|
|
10
|
+
[
|
|
11
|
+
'@nx/react/babel',
|
|
12
|
+
{
|
|
13
|
+
runtime: 'automatic',
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
],
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
presets: [['module:@react-native/babel-preset', { "useTransformReactJSX": true }]],
|
|
22
|
+
};
|
|
23
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en" style="height: 100%">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<title><%= className %></title>
|
|
6
|
+
<base href="/" />
|
|
7
|
+
|
|
8
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
9
|
+
<link rel="icon" type="image/x-icon" href="favicon.ico" />
|
|
10
|
+
</head>
|
|
11
|
+
<body style="height:100%">
|
|
12
|
+
<div id="root" style="display: flex; height: 100%"></div>
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<% if (webpackPluginOptions) { %>
|
|
2
|
+
const { NxWebpackPlugin } = require('@nx/webpack');
|
|
3
|
+
const { NxReactWebpackPlugin } = require('@nx/react');
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
resolve: {
|
|
7
|
+
alias: {
|
|
8
|
+
'react-native$': 'react-native-web',
|
|
9
|
+
},
|
|
10
|
+
extensions: ['.web.tsx', '.web.ts', '.web.jsx', '.web.js']
|
|
11
|
+
},
|
|
12
|
+
devServer: {
|
|
13
|
+
port: 4200
|
|
14
|
+
},
|
|
15
|
+
plugins: [
|
|
16
|
+
new NxWebpackPlugin({
|
|
17
|
+
tsConfig: '<%= webpackPluginOptions.tsConfig %>',
|
|
18
|
+
compiler: '<%= webpackPluginOptions.compiler %>',
|
|
19
|
+
main: '<%= webpackPluginOptions.main %>',
|
|
20
|
+
index: '<%= webpackPluginOptions.index %>',
|
|
21
|
+
outputPath: '<%= webpackPluginOptions.outputPath %>',
|
|
22
|
+
baseHref: '<%= webpackPluginOptions.baseHref %>',
|
|
23
|
+
assets: <%- JSON.stringify(webpackPluginOptions.assets) %>,
|
|
24
|
+
styles: <%- JSON.stringify(webpackPluginOptions.styles) %>,
|
|
25
|
+
outputHashing: process.env['NODE_ENV'] === 'production' ? 'all' : 'none',
|
|
26
|
+
optimization: process.env['NODE_ENV'] === 'production',
|
|
27
|
+
}),
|
|
28
|
+
new NxReactWebpackPlugin({
|
|
29
|
+
// Uncomment this line if you don't want to use SVGR
|
|
30
|
+
// See: https://react-svgr.com/
|
|
31
|
+
// svgr: false
|
|
32
|
+
}),
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
<% } else { %>
|
|
36
|
+
const { composePlugins, withNx } = require('@nx/webpack');
|
|
37
|
+
const { withReact } = require('@nx/react');
|
|
38
|
+
|
|
39
|
+
// Nx plugins for webpack.
|
|
40
|
+
module.exports = composePlugins(
|
|
41
|
+
withNx(),
|
|
42
|
+
withReact({
|
|
43
|
+
// Uncomment this line if you don't want to use SVGR
|
|
44
|
+
// See: https://react-svgr.com/
|
|
45
|
+
// svgr: false
|
|
46
|
+
}),
|
|
47
|
+
(config) => {
|
|
48
|
+
// Update the webpack config as needed here.
|
|
49
|
+
// e.g. `config.plugins.push(new MyPlugin())`
|
|
50
|
+
|
|
51
|
+
config.resolve.alias = {
|
|
52
|
+
...config.resolve.alias ?? {},
|
|
53
|
+
'react-native$': 'react-native-web',
|
|
54
|
+
};
|
|
55
|
+
config.resolve.extensions = [
|
|
56
|
+
'.web.tsx',
|
|
57
|
+
'.web.ts',
|
|
58
|
+
'.web.jsx',
|
|
59
|
+
'.web.js',
|
|
60
|
+
...config.resolve.extensions,
|
|
61
|
+
];
|
|
62
|
+
config.module.rules.push({
|
|
63
|
+
test: /\.(js|jsx)$/,
|
|
64
|
+
include: /react-native-vector-icons/,
|
|
65
|
+
loader: 'babel-loader',
|
|
66
|
+
options: {
|
|
67
|
+
presets: [
|
|
68
|
+
'@babel/preset-env',
|
|
69
|
+
['@babel/preset-react', { runtime: 'automatic' }],
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
return config;
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
<% } %>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Tree } from '@nx/devkit';
|
|
2
|
+
import { WebConfigurationGeneratorSchema } from '../schema';
|
|
3
|
+
export interface NormalizedSchema extends WebConfigurationGeneratorSchema {
|
|
4
|
+
projectRoot: string;
|
|
5
|
+
fileName: string;
|
|
6
|
+
className: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function normalizeSchema(tree: Tree, schema: WebConfigurationGeneratorSchema): {
|
|
9
|
+
projectRoot: string;
|
|
10
|
+
offsetFromRoot: string;
|
|
11
|
+
fileName: string;
|
|
12
|
+
className: string;
|
|
13
|
+
project: string;
|
|
14
|
+
bundler: "vite" | "webpack";
|
|
15
|
+
skipFormat?: boolean;
|
|
16
|
+
skipPackageJson?: boolean;
|
|
17
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeSchema = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
function normalizeSchema(tree, schema) {
|
|
6
|
+
const project = (0, devkit_1.getProjects)(tree).get(schema.project);
|
|
7
|
+
const { fileName, className } = (0, devkit_1.names)(schema.project);
|
|
8
|
+
return {
|
|
9
|
+
...schema,
|
|
10
|
+
projectRoot: project.root,
|
|
11
|
+
offsetFromRoot: (0, devkit_1.offsetFromRoot)(project.root),
|
|
12
|
+
fileName,
|
|
13
|
+
className,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
exports.normalizeSchema = normalizeSchema;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TargetConfiguration } from '@nx/devkit';
|
|
2
|
+
import type { WithReactOptions } from '@nx/react';
|
|
3
|
+
import type { WithNxOptions } from '@nx/webpack';
|
|
4
|
+
import { NormalizedSchema } from './normalize-schema';
|
|
5
|
+
export declare function createBuildTarget(options: NormalizedSchema): TargetConfiguration;
|
|
6
|
+
export declare function createServeTarget(options: NormalizedSchema): TargetConfiguration;
|
|
7
|
+
export declare function createNxWebpackPluginOptions(options: NormalizedSchema): WithNxOptions & WithReactOptions;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createNxWebpackPluginOptions = exports.createServeTarget = exports.createBuildTarget = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
function createBuildTarget(options) {
|
|
6
|
+
return {
|
|
7
|
+
executor: '@nx/webpack:webpack',
|
|
8
|
+
outputs: ['{options.outputPath}'],
|
|
9
|
+
defaultConfiguration: 'production',
|
|
10
|
+
options: {
|
|
11
|
+
compiler: 'babel',
|
|
12
|
+
outputPath: (0, devkit_1.joinPathFragments)('dist', options.projectRoot != '.' ? options.projectRoot : options.project, 'web'),
|
|
13
|
+
index: (0, devkit_1.joinPathFragments)(options.projectRoot, 'src/index.html'),
|
|
14
|
+
baseHref: '/',
|
|
15
|
+
main: (0, devkit_1.joinPathFragments)(options.projectRoot, `src/main-web.tsx`),
|
|
16
|
+
tsConfig: (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.app.json'),
|
|
17
|
+
assets: [
|
|
18
|
+
(0, devkit_1.joinPathFragments)(options.projectRoot, 'src/favicon.ico'),
|
|
19
|
+
(0, devkit_1.joinPathFragments)(options.projectRoot, 'src/assets'),
|
|
20
|
+
],
|
|
21
|
+
webpackConfig: (0, devkit_1.joinPathFragments)(options.projectRoot, 'webpack.config.js'),
|
|
22
|
+
},
|
|
23
|
+
configurations: {
|
|
24
|
+
development: {
|
|
25
|
+
extractLicenses: false,
|
|
26
|
+
optimization: false,
|
|
27
|
+
sourceMap: true,
|
|
28
|
+
vendorChunk: true,
|
|
29
|
+
},
|
|
30
|
+
production: {
|
|
31
|
+
optimization: true,
|
|
32
|
+
outputHashing: 'all',
|
|
33
|
+
sourceMap: false,
|
|
34
|
+
namedChunks: false,
|
|
35
|
+
extractLicenses: true,
|
|
36
|
+
vendorChunk: false,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
exports.createBuildTarget = createBuildTarget;
|
|
42
|
+
function createServeTarget(options) {
|
|
43
|
+
return {
|
|
44
|
+
executor: '@nx/webpack:dev-server',
|
|
45
|
+
defaultConfiguration: 'development',
|
|
46
|
+
options: {
|
|
47
|
+
buildTarget: `${options.project}:build`,
|
|
48
|
+
hmr: true,
|
|
49
|
+
},
|
|
50
|
+
configurations: {
|
|
51
|
+
development: {
|
|
52
|
+
buildTarget: `${options.project}:build:development`,
|
|
53
|
+
},
|
|
54
|
+
production: {
|
|
55
|
+
buildTarget: `${options.project}:build:production`,
|
|
56
|
+
hmr: false,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
exports.createServeTarget = createServeTarget;
|
|
62
|
+
function createNxWebpackPluginOptions(options) {
|
|
63
|
+
return {
|
|
64
|
+
target: 'web',
|
|
65
|
+
compiler: 'babel',
|
|
66
|
+
outputPath: (0, devkit_1.joinPathFragments)('dist', options.projectRoot != '.' ? options.projectRoot : options.project),
|
|
67
|
+
index: './src/index.html',
|
|
68
|
+
baseHref: '/',
|
|
69
|
+
main: `./src/main-web.tsx`,
|
|
70
|
+
tsConfig: './tsconfig.app.json',
|
|
71
|
+
assets: ['./src/favicon.ico', './src/assets'],
|
|
72
|
+
styles: [],
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
exports.createNxWebpackPluginOptions = createNxWebpackPluginOptions;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"$id": "NxReactNativeWebConfiguration",
|
|
4
|
+
"description": "Setup web configuration to React Native apps using react-native-web.",
|
|
5
|
+
"title": "Nx React Native Web configuration",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"project": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"aliases": ["name", "projectName"],
|
|
11
|
+
"description": "Project for which to generate web configuration.",
|
|
12
|
+
"$default": {
|
|
13
|
+
"$source": "argv",
|
|
14
|
+
"index": 0
|
|
15
|
+
},
|
|
16
|
+
"x-prompt": "For which project do you want to generate web configuration?",
|
|
17
|
+
"x-dropdown": "projects",
|
|
18
|
+
"x-priority": "important"
|
|
19
|
+
},
|
|
20
|
+
"skipFormat": {
|
|
21
|
+
"description": "Skip formatting files.",
|
|
22
|
+
"type": "boolean",
|
|
23
|
+
"default": false,
|
|
24
|
+
"x-priority": "internal"
|
|
25
|
+
},
|
|
26
|
+
"skipPackageJson": {
|
|
27
|
+
"description": "Do not add dependencies to `package.json`.",
|
|
28
|
+
"type": "boolean",
|
|
29
|
+
"default": false,
|
|
30
|
+
"x-priority": "internal"
|
|
31
|
+
},
|
|
32
|
+
"bundler": {
|
|
33
|
+
"description": "The bundler to use.",
|
|
34
|
+
"type": "string",
|
|
35
|
+
"enum": ["vite", "webpack"],
|
|
36
|
+
"x-prompt": "Which bundler do you want to use to build the application?",
|
|
37
|
+
"default": "webpack",
|
|
38
|
+
"x-priority": "important"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"required": ["project", "bundler"]
|
|
42
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { GeneratorCallback, Tree } from '@nx/devkit';
|
|
2
|
+
import { WebConfigurationGeneratorSchema } from './schema';
|
|
3
|
+
/**
|
|
4
|
+
* This function sets web configuration for react native apps with react-native-web.
|
|
5
|
+
* 1. install react-native-web
|
|
6
|
+
* 2. apply webpack or vite init generator
|
|
7
|
+
* 3. create files for webpack or vite config, index.html, assets folder, babel.config.js
|
|
8
|
+
* @param tree
|
|
9
|
+
* @param options
|
|
10
|
+
*/
|
|
11
|
+
export declare function webConfigurationGenerator(tree: Tree, options: WebConfigurationGeneratorSchema): Promise<GeneratorCallback>;
|
|
12
|
+
export default webConfigurationGenerator;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.webConfigurationGenerator = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const has_webpack_plugin_1 = require("@nx/react/src/utils/has-webpack-plugin");
|
|
6
|
+
const versions_1 = require("../../utils/versions");
|
|
7
|
+
const normalize_schema_1 = require("./lib/normalize-schema");
|
|
8
|
+
const webpack_targets_1 = require("./lib/webpack-targets");
|
|
9
|
+
/**
|
|
10
|
+
* This function sets web configuration for react native apps with react-native-web.
|
|
11
|
+
* 1. install react-native-web
|
|
12
|
+
* 2. apply webpack or vite init generator
|
|
13
|
+
* 3. create files for webpack or vite config, index.html, assets folder, babel.config.js
|
|
14
|
+
* @param tree
|
|
15
|
+
* @param options
|
|
16
|
+
*/
|
|
17
|
+
async function webConfigurationGenerator(tree, options) {
|
|
18
|
+
const normalizedSchema = (0, normalize_schema_1.normalizeSchema)(tree, options);
|
|
19
|
+
const tasks = [];
|
|
20
|
+
// install react-native-web
|
|
21
|
+
if (!options.skipPackageJson) {
|
|
22
|
+
const installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
|
|
23
|
+
'react-native-web': versions_1.reactNativeWebVersion,
|
|
24
|
+
});
|
|
25
|
+
tasks.push(installTask);
|
|
26
|
+
}
|
|
27
|
+
// apply webpack or vite init generator
|
|
28
|
+
const bundlerTask = await addBundlerConfiguration(tree, normalizedSchema);
|
|
29
|
+
tasks.push(bundlerTask);
|
|
30
|
+
// create files for webpack and vite config, index.html
|
|
31
|
+
if (normalizedSchema.bundler === 'vite') {
|
|
32
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, './files/base-vite'), normalizedSchema.projectRoot, { ...normalizedSchema, tmpl: '' });
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, './files/base-webpack'), normalizedSchema.projectRoot, {
|
|
36
|
+
...normalizedSchema,
|
|
37
|
+
tmpl: '',
|
|
38
|
+
webpackPluginOptions: (0, has_webpack_plugin_1.hasWebpackPlugin)(tree)
|
|
39
|
+
? (0, webpack_targets_1.createNxWebpackPluginOptions)(normalizedSchema)
|
|
40
|
+
: null,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
if (!options.skipFormat) {
|
|
44
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
45
|
+
}
|
|
46
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
47
|
+
}
|
|
48
|
+
exports.webConfigurationGenerator = webConfigurationGenerator;
|
|
49
|
+
/**
|
|
50
|
+
* Add bundler configuration
|
|
51
|
+
* - for vite, viteConfigurationGenerator contains logics to add build and serve target
|
|
52
|
+
* - for webpack, need to explict add the build and serve target
|
|
53
|
+
*/
|
|
54
|
+
async function addBundlerConfiguration(tree, normalizedSchema) {
|
|
55
|
+
if (normalizedSchema.bundler === 'vite') {
|
|
56
|
+
const { viteConfigurationGenerator } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
|
|
57
|
+
const viteTask = await viteConfigurationGenerator(tree, {
|
|
58
|
+
uiFramework: 'react',
|
|
59
|
+
project: normalizedSchema.project,
|
|
60
|
+
newProject: true,
|
|
61
|
+
includeVitest: false,
|
|
62
|
+
compiler: 'babel',
|
|
63
|
+
skipFormat: true,
|
|
64
|
+
});
|
|
65
|
+
return viteTask;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
const { webpackInitGenerator } = (0, devkit_1.ensurePackage)('@nx/webpack', versions_1.nxVersion);
|
|
69
|
+
const webpackInitTask = await webpackInitGenerator(tree, {
|
|
70
|
+
skipFormat: true,
|
|
71
|
+
skipPackageJson: normalizedSchema.skipPackageJson,
|
|
72
|
+
});
|
|
73
|
+
if (!(0, has_webpack_plugin_1.hasWebpackPlugin)(tree)) {
|
|
74
|
+
const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, normalizedSchema.project);
|
|
75
|
+
projectConfiguration.targets = {
|
|
76
|
+
...projectConfiguration.targets,
|
|
77
|
+
build: (0, webpack_targets_1.createBuildTarget)(normalizedSchema),
|
|
78
|
+
serve: (0, webpack_targets_1.createServeTarget)(normalizedSchema),
|
|
79
|
+
};
|
|
80
|
+
(0, devkit_1.updateProjectConfiguration)(tree, normalizedSchema.project, projectConfiguration);
|
|
81
|
+
}
|
|
82
|
+
return webpackInitTask;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.default = webConfigurationGenerator;
|