@empjs/plugin-react 3.0.0-beta.30

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 ADDED
@@ -0,0 +1,16 @@
1
+ # @empjs/plugin-react
2
+ ## 安装
3
+ ```
4
+ pnpm add @empjs/plugin-react -D
5
+ ```
6
+ ## 使用
7
+ ```js
8
+ import pluginReact from '@empjs/plugin-react'
9
+ import {defineConfig} from '@empjs/cli'
10
+ export default defineConfig(({mode, env}) => {
11
+ return {
12
+ plugins: [pluginReact()],
13
+ }
14
+ })
15
+
16
+ ```
@@ -0,0 +1,24 @@
1
+ import type { GlobalStore } from '@empjs/cli';
2
+ export type PluginReactType = {
3
+ /**
4
+ * 是否启动 热更 默认为 true
5
+ */
6
+ hmr?: boolean;
7
+ /**
8
+ * 是否启动 Svg React Component
9
+ * @default ?react
10
+ */
11
+ svgrQuery?: string;
12
+ /**
13
+ * React Runtime 手动切换jsx模式
14
+ * 当 external react时需要设置
15
+ * 本地安装时会自动判断 不需要设置
16
+ * @default undefined
17
+ */
18
+ reactRuntime?: string;
19
+ };
20
+ declare const _default: (o: PluginReactType) => {
21
+ name: string;
22
+ rsConfig(store: GlobalStore): Promise<void>;
23
+ };
24
+ export default _default;
package/dist/index.js ADDED
@@ -0,0 +1,87 @@
1
+ //
2
+ export default (o) => {
3
+ return {
4
+ name: '@empjs/plugin-react',
5
+ async rsConfig(store) {
6
+ const { chain, deepAssign } = store;
7
+ o = deepAssign({ hmr: true, svgrQuery: 'react' }, o);
8
+ //
9
+ const reactVersion = store.pkg.dependencies.react || store.pkg.devDependencies.react;
10
+ if (!reactVersion) {
11
+ throw new Error('React must be installed!');
12
+ }
13
+ //
14
+ function getReactRuntime() {
15
+ if (!reactVersion)
16
+ return o.reactRuntime;
17
+ return o.reactRuntime ? o.reactRuntime : store.vCompare(reactVersion, '17') > -1 ? 'automatic' : 'classic';
18
+ }
19
+ const reactRuntime = getReactRuntime();
20
+ /** ======================
21
+ * swc transform 配置
22
+ * =======================
23
+ */
24
+ const transform = {
25
+ react: {
26
+ runtime: reactRuntime,
27
+ development: store.isDev,
28
+ refresh: store.isDev,
29
+ },
30
+ };
31
+ const resetTransform = (op) => {
32
+ op.jsc.transform = deepAssign(op.jsc.transform, transform);
33
+ return op;
34
+ };
35
+ //
36
+ chain.module.rule('javascript').use('swc').tap(resetTransform);
37
+ chain.module.rule('typescript').use('swc').tap(resetTransform);
38
+ /** ======================
39
+ * swc hmr 配置
40
+ * =======================
41
+ */
42
+ if (store.isDev && o.hmr) {
43
+ const { default: ReactRefresh } = await import('@rspack/plugin-react-refresh');
44
+ const op = {
45
+ // overlay: false,
46
+ };
47
+ if (store.empConfig.empShareLib.config.name) {
48
+ op.library = store.empConfig.empShareLib.config.name;
49
+ }
50
+ store.chain.plugin('plugin-react-refresh').use(ReactRefresh, [op]);
51
+ }
52
+ /** ======================
53
+ * swc svgr 配置
54
+ * =======================
55
+ */
56
+ chain.module.rule('svg').delete('type');
57
+ //
58
+ const exp = new RegExp(`${o.svgrQuery}`);
59
+ store.chain.merge({
60
+ module: {
61
+ rule: {
62
+ svg: {
63
+ test: /\.svg$/,
64
+ oneOf: [
65
+ {
66
+ issuer: /\.[jt]sx?$/,
67
+ resourceQuery: exp,
68
+ use: [
69
+ {
70
+ loader: store.importResolve('@svgr/webpack'),
71
+ options: {},
72
+ },
73
+ ],
74
+ },
75
+ {
76
+ resourceQuery: { not: [exp] },
77
+ type: 'asset/resource',
78
+ },
79
+ ],
80
+ },
81
+ },
82
+ },
83
+ });
84
+ //
85
+ },
86
+ };
87
+ };
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@empjs/plugin-react",
3
+ "version": "3.0.0-beta.30",
4
+ "description": "emp react plugin",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "maintainers": [
11
+ "xuhongbin",
12
+ "ckken"
13
+ ],
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/empjs/emp.git",
17
+ "directory": "packages/plugin-react"
18
+ },
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "keywords": [
23
+ "vue",
24
+ "vue2"
25
+ ],
26
+ "main": "dist/index.js",
27
+ "types": "dist/index.d.ts",
28
+ "exports": {
29
+ ".": "./dist/index.js"
30
+ },
31
+ "scripts": {
32
+ "dev": "rimraf dist && pnpm run /^dev:.*/",
33
+ "dev:tsc": "tsc -w",
34
+ "dev:tsc-alias": "tsc-alias -w",
35
+ "build": "rimraf dist && pnpm run /^build:.*/",
36
+ "build:ts": "tsc && tsc-alias"
37
+ },
38
+ "engines": {
39
+ "node": ">=20.0.0"
40
+ },
41
+ "author": "Ken",
42
+ "devDependencies": {
43
+ "@empjs/cli": "workspace:*",
44
+ "@types/react": "^18.2.30",
45
+ "rimraf": "^5.0.5",
46
+ "tsc-alias": "^1.8.8"
47
+ },
48
+ "dependencies": {
49
+ "react-refresh": "^0.14.0",
50
+ "@rspack/plugin-react-refresh": "0.5.9"
51
+ }
52
+ }