@tarojs/plugin-framework-react 3.5.0-canary.1 → 3.5.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/dist/api-loader.js +72 -54
- package/dist/api-loader.js.map +1 -1
- package/dist/index.js +259 -194
- package/dist/index.js.map +1 -1
- package/dist/runtime.js +646 -545
- package/dist/runtime.js.map +1 -1
- package/index.js +1 -0
- package/package.json +23 -14
package/dist/api-loader.js
CHANGED
|
@@ -1,62 +1,80 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
function apiLoader (str) {
|
|
3
|
+
function apiLoader (str) {
|
|
4
4
|
return `import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
5
|
+
useAddToFavorites,
|
|
6
|
+
useDidHide,
|
|
7
|
+
useDidShow,
|
|
8
|
+
useError,
|
|
9
|
+
useLaunch,
|
|
10
|
+
useLoad,
|
|
11
|
+
useOptionMenuClick,
|
|
12
|
+
usePageNotFound,
|
|
13
|
+
usePageScroll,
|
|
14
|
+
usePullDownRefresh,
|
|
15
|
+
usePullIntercept,
|
|
16
|
+
useReachBottom,
|
|
17
|
+
useReady,
|
|
18
|
+
useResize,
|
|
19
|
+
useRouter,
|
|
20
|
+
useSaveExitState,
|
|
21
|
+
useShareAppMessage,
|
|
22
|
+
useShareTimeline,
|
|
23
|
+
useTabItemTap,
|
|
24
|
+
useTitleClick,
|
|
25
|
+
useScope,
|
|
26
|
+
useUnload
|
|
27
|
+
} from '@tarojs/plugin-framework-react/dist/runtime'
|
|
28
|
+
${str}
|
|
23
29
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
taro.useAddToFavorites = useAddToFavorites
|
|
31
|
+
taro.useDidHide = useDidHide
|
|
32
|
+
taro.useDidShow = useDidShow
|
|
33
|
+
taro.useError = useError
|
|
34
|
+
taro.useLaunch = useLaunch
|
|
35
|
+
taro.useLoad = useLoad
|
|
36
|
+
taro.useOptionMenuClick = useOptionMenuClick
|
|
37
|
+
taro.usePageNotFound = usePageNotFound
|
|
38
|
+
taro.usePageScroll = usePageScroll
|
|
39
|
+
taro.usePullDownRefresh = usePullDownRefresh
|
|
40
|
+
taro.usePullIntercept = usePullIntercept
|
|
41
|
+
taro.useReachBottom = useReachBottom
|
|
42
|
+
taro.useReady = useReady
|
|
43
|
+
taro.useResize = useResize
|
|
44
|
+
taro.useRouter = useRouter
|
|
45
|
+
taro.useSaveExitState = useSaveExitState
|
|
46
|
+
taro.useShareAppMessage = useShareAppMessage
|
|
47
|
+
taro.useShareTimeline = useShareTimeline
|
|
48
|
+
taro.useTabItemTap = useTabItemTap
|
|
49
|
+
taro.useTitleClick = useTitleClick
|
|
50
|
+
taro.useScope = useScope
|
|
51
|
+
taro.useUnload = useUnload
|
|
40
52
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
53
|
+
export {
|
|
54
|
+
useAddToFavorites,
|
|
55
|
+
useDidHide,
|
|
56
|
+
useDidShow,
|
|
57
|
+
useError,
|
|
58
|
+
useLaunch,
|
|
59
|
+
useLoad,
|
|
60
|
+
useOptionMenuClick,
|
|
61
|
+
usePageNotFound,
|
|
62
|
+
usePageScroll,
|
|
63
|
+
usePullDownRefresh,
|
|
64
|
+
usePullIntercept,
|
|
65
|
+
useReachBottom,
|
|
66
|
+
useReady,
|
|
67
|
+
useResize,
|
|
68
|
+
useRouter,
|
|
69
|
+
useSaveExitState,
|
|
70
|
+
useShareAppMessage,
|
|
71
|
+
useShareTimeline,
|
|
72
|
+
useTabItemTap,
|
|
73
|
+
useTitleClick,
|
|
74
|
+
useScope,
|
|
75
|
+
useUnload
|
|
76
|
+
}
|
|
77
|
+
`;
|
|
60
78
|
}
|
|
61
79
|
|
|
62
80
|
module.exports = apiLoader;
|
package/dist/api-loader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-loader.js","sources":["../src/api-loader.ts"],"sourcesContent":["export default function (str) {\n return `import {\n
|
|
1
|
+
{"version":3,"file":"api-loader.js","sources":["../src/api-loader.ts"],"sourcesContent":["export default function (str) {\n return `import {\n useAddToFavorites,\n useDidHide,\n useDidShow,\n useError,\n useLaunch,\n useLoad,\n useOptionMenuClick,\n usePageNotFound,\n usePageScroll,\n usePullDownRefresh,\n usePullIntercept,\n useReachBottom,\n useReady,\n useResize,\n useRouter,\n useSaveExitState,\n useShareAppMessage,\n useShareTimeline,\n useTabItemTap,\n useTitleClick,\n useScope,\n useUnload\n} from '@tarojs/plugin-framework-react/dist/runtime'\n${str}\n\ntaro.useAddToFavorites = useAddToFavorites\ntaro.useDidHide = useDidHide\ntaro.useDidShow = useDidShow\ntaro.useError = useError\ntaro.useLaunch = useLaunch\ntaro.useLoad = useLoad\ntaro.useOptionMenuClick = useOptionMenuClick\ntaro.usePageNotFound = usePageNotFound\ntaro.usePageScroll = usePageScroll\ntaro.usePullDownRefresh = usePullDownRefresh\ntaro.usePullIntercept = usePullIntercept\ntaro.useReachBottom = useReachBottom\ntaro.useReady = useReady\ntaro.useResize = useResize\ntaro.useRouter = useRouter\ntaro.useSaveExitState = useSaveExitState\ntaro.useShareAppMessage = useShareAppMessage\ntaro.useShareTimeline = useShareTimeline\ntaro.useTabItemTap = useTabItemTap\ntaro.useTitleClick = useTitleClick\ntaro.useScope = useScope\ntaro.useUnload = useUnload\n\nexport {\n useAddToFavorites,\n useDidHide,\n useDidShow,\n useError,\n useLaunch,\n useLoad,\n useOptionMenuClick,\n usePageNotFound,\n usePageScroll,\n usePullDownRefresh,\n usePullIntercept,\n useReachBottom,\n useReady,\n useResize,\n useRouter,\n useSaveExitState,\n useShareAppMessage,\n useShareTimeline,\n useTabItemTap,\n useTitleClick,\n useScope,\n useUnload\n}\n`\n}\n"],"names":[],"mappings":";;AAAc,kBAAA,EAAW,GAAG,EAAA;IACxB,OAAO,CAAA;;;;;;;;;;;;;;;;;;;;;;;;EAwBT,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiDJ,CAAC;AACF;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var helper = require('@tarojs/helper');
|
|
6
|
+
var shared = require('@tarojs/shared');
|
|
5
7
|
var acorn = require('acorn');
|
|
6
8
|
var walk = require('acorn-walk');
|
|
7
9
|
|
|
@@ -14,233 +16,296 @@ function _interopNamespace(e) {
|
|
|
14
16
|
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
17
|
Object.defineProperty(n, k, d.get ? d : {
|
|
16
18
|
enumerable: true,
|
|
17
|
-
get: function () {
|
|
18
|
-
return e[k];
|
|
19
|
-
}
|
|
19
|
+
get: function () { return e[k]; }
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
|
-
n[
|
|
24
|
+
n["default"] = e;
|
|
25
25
|
return Object.freeze(n);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
var acorn__namespace = /*#__PURE__*/_interopNamespace(acorn);
|
|
29
29
|
var walk__namespace = /*#__PURE__*/_interopNamespace(walk);
|
|
30
30
|
|
|
31
|
-
function addConfig(source) {
|
|
32
|
-
const configsMap = {
|
|
33
|
-
enableShareAppMessage: ['onShareAppMessage', 'useShareAppMessage'],
|
|
34
|
-
enableShareTimeline: ['onShareTimeline', 'useShareTimeline']
|
|
35
|
-
};
|
|
36
|
-
const ast = acorn__namespace.parse(source, {
|
|
37
|
-
ecmaVersion: 'latest',
|
|
38
|
-
sourceType: 'module'
|
|
39
|
-
});
|
|
40
|
-
const additionConfig = {};
|
|
41
|
-
function check(name) {
|
|
42
|
-
Object.keys(configsMap).forEach(configName => {
|
|
43
|
-
const apis = configsMap[configName];
|
|
44
|
-
if (apis.includes(name)) {
|
|
45
|
-
additionConfig[configName] = true;
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
walk__namespace.simple(ast, {
|
|
50
|
-
FunctionExpression(node) {
|
|
51
|
-
if (!node.id || !node.id.name)
|
|
52
|
-
return;
|
|
53
|
-
check(node.id.name);
|
|
54
|
-
},
|
|
55
|
-
FunctionDeclaration(node) {
|
|
56
|
-
if (!node.id || !node.id.name)
|
|
57
|
-
return;
|
|
58
|
-
check(node.id.name);
|
|
59
|
-
},
|
|
60
|
-
CallExpression(node) {
|
|
61
|
-
const { callee } = node;
|
|
62
|
-
if (callee.type === 'Identifier') {
|
|
63
|
-
check(callee.name);
|
|
64
|
-
}
|
|
65
|
-
else if (callee.type === 'MemberExpression') {
|
|
66
|
-
if (callee.property.type === 'Identifier') {
|
|
67
|
-
check(callee.property.name);
|
|
68
|
-
}
|
|
69
|
-
else if (callee.property.type === 'Literal') {
|
|
70
|
-
check(callee.property.value);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
return additionConfig;
|
|
76
|
-
}
|
|
77
|
-
const frameworkMeta = {
|
|
78
|
-
nerv: {
|
|
31
|
+
function addConfig(source) {
|
|
32
|
+
const configsMap = {
|
|
33
|
+
enableShareAppMessage: ['onShareAppMessage', 'useShareAppMessage'],
|
|
34
|
+
enableShareTimeline: ['onShareTimeline', 'useShareTimeline']
|
|
35
|
+
};
|
|
36
|
+
const ast = acorn__namespace.parse(source, {
|
|
37
|
+
ecmaVersion: 'latest',
|
|
38
|
+
sourceType: 'module'
|
|
39
|
+
});
|
|
40
|
+
const additionConfig = {};
|
|
41
|
+
function check(name) {
|
|
42
|
+
Object.keys(configsMap).forEach(configName => {
|
|
43
|
+
const apis = configsMap[configName];
|
|
44
|
+
if (apis.includes(name)) {
|
|
45
|
+
additionConfig[configName] = true;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
walk__namespace.simple(ast, {
|
|
50
|
+
FunctionExpression(node) {
|
|
51
|
+
if (!node.id || !node.id.name)
|
|
52
|
+
return;
|
|
53
|
+
check(node.id.name);
|
|
54
|
+
},
|
|
55
|
+
FunctionDeclaration(node) {
|
|
56
|
+
if (!node.id || !node.id.name)
|
|
57
|
+
return;
|
|
58
|
+
check(node.id.name);
|
|
59
|
+
},
|
|
60
|
+
CallExpression(node) {
|
|
61
|
+
const { callee } = node;
|
|
62
|
+
if (callee.type === 'Identifier') {
|
|
63
|
+
check(callee.name);
|
|
64
|
+
}
|
|
65
|
+
else if (callee.type === 'MemberExpression') {
|
|
66
|
+
if (callee.property.type === 'Identifier') {
|
|
67
|
+
check(callee.property.name);
|
|
68
|
+
}
|
|
69
|
+
else if (callee.property.type === 'Literal') {
|
|
70
|
+
check(callee.property.value);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
return additionConfig;
|
|
76
|
+
}
|
|
77
|
+
const frameworkMeta = {
|
|
78
|
+
nerv: {
|
|
79
79
|
importFrameworkStatement: `
|
|
80
80
|
import Nerv from 'nervjs';
|
|
81
|
-
`,
|
|
81
|
+
`,
|
|
82
82
|
mockAppStatement: `
|
|
83
83
|
class App extends Nerv.Component {
|
|
84
84
|
render () {
|
|
85
85
|
return this.props.children
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
`,
|
|
89
|
-
frameworkArgs: 'Nerv, Nerv, config',
|
|
90
|
-
creator: 'createReactApp',
|
|
91
|
-
creatorLocation: '@tarojs/plugin-framework-react/dist/runtime',
|
|
92
|
-
importFrameworkName: 'Nerv',
|
|
93
|
-
modifyConfig(config, source) {
|
|
94
|
-
Object.assign(config, addConfig(source));
|
|
95
|
-
}
|
|
96
|
-
},
|
|
97
|
-
react: {
|
|
88
|
+
`,
|
|
89
|
+
frameworkArgs: 'Nerv, Nerv, config',
|
|
90
|
+
creator: 'createReactApp',
|
|
91
|
+
creatorLocation: '@tarojs/plugin-framework-react/dist/runtime',
|
|
92
|
+
importFrameworkName: 'Nerv',
|
|
93
|
+
modifyConfig(config, source) {
|
|
94
|
+
Object.assign(config, addConfig(source));
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
react: {
|
|
98
98
|
importFrameworkStatement: `
|
|
99
99
|
import * as React from 'react'
|
|
100
100
|
import ReactDOM from 'react-dom'
|
|
101
|
-
`,
|
|
101
|
+
`,
|
|
102
102
|
mockAppStatement: `
|
|
103
103
|
class App extends React.Component {
|
|
104
104
|
render () {
|
|
105
105
|
return this.props.children
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
|
-
`,
|
|
109
|
-
frameworkArgs: 'React, ReactDOM, config',
|
|
110
|
-
creator: 'createReactApp',
|
|
111
|
-
creatorLocation: '@tarojs/plugin-framework-react/dist/runtime',
|
|
112
|
-
importFrameworkName: 'React',
|
|
113
|
-
compatComponentImport: 'import { PullDownRefresh } from "@tarojs/components"',
|
|
114
|
-
compatComponentExtra: 'config.PullDownRefresh = PullDownRefresh',
|
|
115
|
-
modifyConfig(config, source) {
|
|
116
|
-
Object.assign(config, addConfig(source));
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
function getLoaderMeta(framework) {
|
|
121
|
-
if (framework === 'preact')
|
|
122
|
-
framework = 'react';
|
|
123
|
-
return frameworkMeta[framework];
|
|
108
|
+
`,
|
|
109
|
+
frameworkArgs: 'React, ReactDOM, config',
|
|
110
|
+
creator: 'createReactApp',
|
|
111
|
+
creatorLocation: '@tarojs/plugin-framework-react/dist/runtime',
|
|
112
|
+
importFrameworkName: 'React',
|
|
113
|
+
compatComponentImport: 'import { PullDownRefresh } from "@tarojs/components"',
|
|
114
|
+
compatComponentExtra: 'config.PullDownRefresh = PullDownRefresh',
|
|
115
|
+
modifyConfig(config, source) {
|
|
116
|
+
Object.assign(config, addConfig(source));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
function getLoaderMeta(framework) {
|
|
121
|
+
if (framework === 'preact')
|
|
122
|
+
framework = 'react';
|
|
123
|
+
return frameworkMeta[framework];
|
|
124
|
+
}
|
|
125
|
+
// In react 18 or above, should using react-dom/client
|
|
126
|
+
function getLoaderMetaForH5(framework) {
|
|
127
|
+
const loaderMeta = getLoaderMeta(framework);
|
|
128
|
+
if (framework === 'react') {
|
|
129
|
+
const react = require('react');
|
|
130
|
+
const majorVersion = Number((react.version || '18').split('.')[0]);
|
|
131
|
+
if (majorVersion >= 18) {
|
|
132
|
+
loaderMeta.importFrameworkStatement = loaderMeta.importFrameworkStatement.replace("'react-dom'", "'react-dom/client'");
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return loaderMeta;
|
|
124
136
|
}
|
|
125
137
|
|
|
126
|
-
function
|
|
127
|
-
setAlias$2(ctx,
|
|
128
|
-
setLoader$1(framework, chain);
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
138
|
+
function modifyH5WebpackChain(ctx, framework, chain) {
|
|
139
|
+
setAlias$2(ctx, chain);
|
|
140
|
+
setLoader$1(framework, chain);
|
|
141
|
+
setPlugin(ctx, framework, chain);
|
|
142
|
+
chain.merge({
|
|
143
|
+
module: {
|
|
144
|
+
rule: {
|
|
145
|
+
'process-import-taro': {
|
|
146
|
+
test: /taro-h5[\\/]dist[\\/]index/,
|
|
147
|
+
loader: require.resolve('./api-loader')
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
function setAlias$2(ctx, chain) {
|
|
154
|
+
var _a;
|
|
155
|
+
const config = ctx.initialConfig;
|
|
156
|
+
const alias = chain.resolve.alias;
|
|
157
|
+
if ((_a = config.h5) === null || _a === void 0 ? void 0 : _a.useHtmlComponents) {
|
|
158
|
+
alias.set('@tarojs/components$', '@tarojs/components-react/index');
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
alias.set('@tarojs/components$', '@tarojs/components/dist-h5/react');
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function setLoader$1(framework, chain) {
|
|
165
|
+
chain.plugin('mainPlugin')
|
|
166
|
+
.tap(args => {
|
|
167
|
+
args[0].loaderMeta = getLoaderMetaForH5(framework);
|
|
168
|
+
return args;
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
function setPlugin(ctx, framework, chain) {
|
|
172
|
+
var _a, _b;
|
|
173
|
+
const config = ctx.initialConfig;
|
|
174
|
+
if (process.env.NODE_ENV !== 'production' &&
|
|
175
|
+
((_b = (_a = config.h5) === null || _a === void 0 ? void 0 : _a.devServer) === null || _b === void 0 ? void 0 : _b.hot) !== false) {
|
|
176
|
+
// 默认开启 fast-refresh
|
|
177
|
+
if (framework === 'react') {
|
|
178
|
+
chain
|
|
179
|
+
.plugin('fastRefreshPlugin')
|
|
180
|
+
.use(require('@pmmmwh/react-refresh-webpack-plugin'));
|
|
181
|
+
}
|
|
182
|
+
else if (framework === 'preact') {
|
|
183
|
+
chain
|
|
184
|
+
.plugin('fastRefreshPlugin')
|
|
185
|
+
.use(require('@prefresh/webpack'));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
151
188
|
}
|
|
152
189
|
|
|
153
|
-
function
|
|
154
|
-
setAlias$1(ctx, chain);
|
|
155
|
-
setLoader(framework, chain);
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
// 默认开启 fast-refresh
|
|
192
|
-
if (framework === 'react') {
|
|
193
|
-
chain
|
|
194
|
-
.plugin('fastRefreshPlugin')
|
|
195
|
-
.use(require('@pmmmwh/react-refresh-webpack-plugin'));
|
|
196
|
-
}
|
|
197
|
-
else if (framework === 'preact') {
|
|
198
|
-
chain
|
|
199
|
-
.plugin('fastRefreshPlugin')
|
|
200
|
-
.use(require('@prefresh/webpack'));
|
|
201
|
-
}
|
|
202
|
-
}
|
|
190
|
+
function modifyMiniWebpackChain(ctx, framework, chain) {
|
|
191
|
+
setAlias$1(ctx, framework, chain);
|
|
192
|
+
setLoader(framework, chain);
|
|
193
|
+
}
|
|
194
|
+
function setAlias$1(ctx, framework, chain) {
|
|
195
|
+
var _a;
|
|
196
|
+
const config = ctx.initialConfig;
|
|
197
|
+
const alias = chain.resolve.alias;
|
|
198
|
+
if (framework === 'react') {
|
|
199
|
+
alias.set('react-dom$', '@tarojs/react');
|
|
200
|
+
if (process.env.NODE_ENV !== 'production' && ((_a = config.mini) === null || _a === void 0 ? void 0 : _a.debugReact) !== true) {
|
|
201
|
+
// 不是生产环境,且没有设置 debugReact,则使用压缩版本的 react 依赖,减少体积
|
|
202
|
+
alias.set('react-reconciler$', 'react-reconciler/cjs/react-reconciler.production.min.js');
|
|
203
|
+
alias.set('react$', 'react/cjs/react.production.min.js');
|
|
204
|
+
alias.set('scheduler$', 'scheduler/cjs/scheduler.production.min.js');
|
|
205
|
+
alias.set('react/jsx-runtime$', 'react/cjs/react-jsx-runtime.production.min.js');
|
|
206
|
+
// 在React18中,使用了exports字段约定了模块暴露路径,其中并未暴露 ./cjs/ 。这将使上面的alias在编译时报错。相当的tricky。
|
|
207
|
+
// Why writeJson? prebundle will load package.json via readFile to check exports property.
|
|
208
|
+
const reactPkgPath = require.resolve('react/package.json', { paths: [process.cwd()] });
|
|
209
|
+
if (reactPkgPath) {
|
|
210
|
+
const reactPkg = require('react/package.json');
|
|
211
|
+
const reactVersion = (reactPkg.version || '');
|
|
212
|
+
if ((/^[~^]?18/).test(reactVersion) && reactPkg.exports) {
|
|
213
|
+
reactPkg.exports = Object.assign(reactPkg.exports, {
|
|
214
|
+
'./cjs/': './cjs/'
|
|
215
|
+
});
|
|
216
|
+
helper.fs.writeJsonSync(reactPkgPath, reactPkg, { spaces: 2 });
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
function setLoader(framework, chain) {
|
|
223
|
+
chain.plugin('miniPlugin')
|
|
224
|
+
.tap(args => {
|
|
225
|
+
args[0].loaderMeta = getLoaderMeta(framework);
|
|
226
|
+
return args;
|
|
227
|
+
});
|
|
203
228
|
}
|
|
204
229
|
|
|
205
|
-
var index = (ctx) => {
|
|
206
|
-
const { framework } = ctx.initialConfig;
|
|
207
|
-
if (framework !== 'react' && framework !== 'nerv' && framework !== 'preact')
|
|
208
|
-
return;
|
|
209
|
-
ctx.modifyWebpackChain(({ chain }) => {
|
|
210
|
-
// 通用
|
|
211
|
-
setAlias(framework, chain);
|
|
212
|
-
chain
|
|
213
|
-
.plugin('definePlugin')
|
|
214
|
-
.tap(args => {
|
|
215
|
-
const config = args[0];
|
|
216
|
-
config.__TARO_FRAMEWORK__ = `"${framework}"`;
|
|
217
|
-
return args;
|
|
218
|
-
});
|
|
219
|
-
if (process.env.TARO_ENV === 'h5') {
|
|
220
|
-
// H5
|
|
221
|
-
modifyH5WebpackChain(ctx, framework, chain);
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
// 小程序
|
|
225
|
-
modifyMiniWebpackChain(ctx, framework, chain);
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
230
|
+
var index = (ctx) => {
|
|
231
|
+
const { framework } = ctx.initialConfig;
|
|
232
|
+
if (framework !== 'react' && framework !== 'nerv' && framework !== 'preact')
|
|
233
|
+
return;
|
|
234
|
+
ctx.modifyWebpackChain(({ chain }) => {
|
|
235
|
+
// 通用
|
|
236
|
+
setAlias(framework, chain);
|
|
237
|
+
chain
|
|
238
|
+
.plugin('definePlugin')
|
|
239
|
+
.tap(args => {
|
|
240
|
+
const config = args[0];
|
|
241
|
+
config.__TARO_FRAMEWORK__ = `"${framework}"`;
|
|
242
|
+
return args;
|
|
243
|
+
});
|
|
244
|
+
if (process.env.TARO_ENV === 'h5') {
|
|
245
|
+
// H5
|
|
246
|
+
modifyH5WebpackChain(ctx, framework, chain);
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
// 小程序
|
|
250
|
+
modifyMiniWebpackChain(ctx, framework, chain);
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
ctx.modifyRunnerOpts(({ opts }) => {
|
|
254
|
+
if (!(opts === null || opts === void 0 ? void 0 : opts.compiler))
|
|
255
|
+
return;
|
|
256
|
+
if (shared.isString(opts.compiler)) {
|
|
257
|
+
opts.compiler = {
|
|
258
|
+
type: opts.compiler
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
const { compiler } = opts;
|
|
262
|
+
if (compiler.type === 'webpack5') {
|
|
263
|
+
// 提供给 webpack5 依赖预编译收集器的第三方依赖
|
|
264
|
+
const deps = [
|
|
265
|
+
'react',
|
|
266
|
+
'react-dom',
|
|
267
|
+
'react/jsx-runtime',
|
|
268
|
+
'@tarojs/plugin-framework-react/dist/runtime'
|
|
269
|
+
];
|
|
270
|
+
compiler.prebundle || (compiler.prebundle = {});
|
|
271
|
+
const prebundleOptions = compiler.prebundle;
|
|
272
|
+
prebundleOptions.include || (prebundleOptions.include = []);
|
|
273
|
+
prebundleOptions.include = prebundleOptions.include.concat(deps);
|
|
274
|
+
if (prebundleOptions.enable === false)
|
|
275
|
+
return;
|
|
276
|
+
const taroReactPlugin = {
|
|
277
|
+
name: 'taroReactPlugin',
|
|
278
|
+
setup(build) {
|
|
279
|
+
build.onLoad({ filter: /taro-h5[\\/]dist[\\/]index/ }, ({ path }) => {
|
|
280
|
+
const content = helper.fs.readFileSync(path).toString();
|
|
281
|
+
return {
|
|
282
|
+
contents: require('./api-loader')(content)
|
|
283
|
+
};
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
prebundleOptions.esbuild || (prebundleOptions.esbuild = {});
|
|
288
|
+
const esbuildConfig = prebundleOptions.esbuild;
|
|
289
|
+
esbuildConfig.plugins || (esbuildConfig.plugins = []);
|
|
290
|
+
esbuildConfig.plugins.push(taroReactPlugin);
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
};
|
|
294
|
+
function setAlias(framework, chain) {
|
|
295
|
+
const alias = chain.resolve.alias;
|
|
296
|
+
switch (framework) {
|
|
297
|
+
case 'preact':
|
|
298
|
+
alias.set('react', 'preact/compat');
|
|
299
|
+
alias.set('react-dom/test-utils', 'preact/test-utils');
|
|
300
|
+
alias.set('react-dom', 'preact/compat');
|
|
301
|
+
alias.set('react/jsx-runtime', 'preact/jsx-runtime');
|
|
302
|
+
break;
|
|
303
|
+
case 'nerv':
|
|
304
|
+
alias.set('react$', 'nervjs');
|
|
305
|
+
alias.set('react-dom$', 'nervjs');
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
243
308
|
}
|
|
244
309
|
|
|
245
|
-
exports[
|
|
310
|
+
exports["default"] = index;
|
|
246
311
|
//# sourceMappingURL=index.js.map
|