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