@tarojs/plugin-framework-solid 4.0.0-beta.84 → 4.0.0-beta.85
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 +84 -0
- package/dist/api-loader.js.map +1 -0
- package/dist/index.js +550 -0
- package/dist/index.js.map +1 -0
- package/dist/reconciler.js +187 -0
- package/dist/reconciler.js.map +1 -0
- package/dist/runtime.js +327 -0
- package/dist/runtime.js.map +1 -0
- package/package.json +9 -9
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function apiLoader (str) {
|
|
4
|
+
return `import {
|
|
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
|
+
useUnhandledRejection,
|
|
27
|
+
useUnload
|
|
28
|
+
} from '@tarojs/plugin-framework-solid/dist/runtime'
|
|
29
|
+
${str}
|
|
30
|
+
|
|
31
|
+
taro.useAddToFavorites = useAddToFavorites
|
|
32
|
+
taro.useDidHide = useDidHide
|
|
33
|
+
taro.useDidShow = useDidShow
|
|
34
|
+
taro.useError = useError
|
|
35
|
+
taro.useLaunch = useLaunch
|
|
36
|
+
taro.useLoad = useLoad
|
|
37
|
+
taro.useOptionMenuClick = useOptionMenuClick
|
|
38
|
+
taro.usePageNotFound = usePageNotFound
|
|
39
|
+
taro.usePageScroll = usePageScroll
|
|
40
|
+
taro.usePullDownRefresh = usePullDownRefresh
|
|
41
|
+
taro.usePullIntercept = usePullIntercept
|
|
42
|
+
taro.useReachBottom = useReachBottom
|
|
43
|
+
taro.useReady = useReady
|
|
44
|
+
taro.useResize = useResize
|
|
45
|
+
taro.useRouter = useRouter
|
|
46
|
+
taro.useSaveExitState = useSaveExitState
|
|
47
|
+
taro.useShareAppMessage = useShareAppMessage
|
|
48
|
+
taro.useShareTimeline = useShareTimeline
|
|
49
|
+
taro.useTabItemTap = useTabItemTap
|
|
50
|
+
taro.useTitleClick = useTitleClick
|
|
51
|
+
taro.useScope = useScope
|
|
52
|
+
taro.useUnhandledRejection = useUnhandledRejection
|
|
53
|
+
taro.useUnload = useUnload
|
|
54
|
+
|
|
55
|
+
export {
|
|
56
|
+
useAddToFavorites,
|
|
57
|
+
useDidHide,
|
|
58
|
+
useDidShow,
|
|
59
|
+
useError,
|
|
60
|
+
useLaunch,
|
|
61
|
+
useLoad,
|
|
62
|
+
useOptionMenuClick,
|
|
63
|
+
usePageNotFound,
|
|
64
|
+
usePageScroll,
|
|
65
|
+
usePullDownRefresh,
|
|
66
|
+
usePullIntercept,
|
|
67
|
+
useReachBottom,
|
|
68
|
+
useReady,
|
|
69
|
+
useResize,
|
|
70
|
+
useRouter,
|
|
71
|
+
useSaveExitState,
|
|
72
|
+
useShareAppMessage,
|
|
73
|
+
useShareTimeline,
|
|
74
|
+
useTabItemTap,
|
|
75
|
+
useTitleClick,
|
|
76
|
+
useScope,
|
|
77
|
+
useUnhandledRejection,
|
|
78
|
+
useUnload
|
|
79
|
+
}
|
|
80
|
+
`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
module.exports = apiLoader;
|
|
84
|
+
//# sourceMappingURL=api-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-loader.js","sources":["../src/api-loader.ts"],"sourcesContent":["export default function (str: string) {\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 useUnhandledRejection,\n useUnload\n} from '@tarojs/plugin-framework-solid/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.useUnhandledRejection = useUnhandledRejection\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 useUnhandledRejection,\n useUnload\n}\n`\n}\n"],"names":[],"mappings":";;AAAc,kBAAA,EAAW,GAAW,EAAA;IAClC,OAAO,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;EAyBP,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmDJ,CAAA;AACD;;;;"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,550 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var helper = require('@tarojs/helper');
|
|
6
|
+
var shared = require('@tarojs/shared');
|
|
7
|
+
var lodash = require('lodash');
|
|
8
|
+
var acorn = require('acorn');
|
|
9
|
+
var walk = require('acorn-walk');
|
|
10
|
+
|
|
11
|
+
function _interopNamespaceDefault(e) {
|
|
12
|
+
var n = Object.create(null);
|
|
13
|
+
if (e) {
|
|
14
|
+
Object.keys(e).forEach(function (k) {
|
|
15
|
+
if (k !== 'default') {
|
|
16
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return e[k]; }
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
n.default = e;
|
|
25
|
+
return Object.freeze(n);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var acorn__namespace = /*#__PURE__*/_interopNamespaceDefault(acorn);
|
|
29
|
+
var walk__namespace = /*#__PURE__*/_interopNamespaceDefault(walk);
|
|
30
|
+
|
|
31
|
+
const RECONCILER_NAME = '@tarojs/plugin-framework-solid/dist/reconciler';
|
|
32
|
+
|
|
33
|
+
/******************************************************************************
|
|
34
|
+
Copyright (c) Microsoft Corporation.
|
|
35
|
+
|
|
36
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
37
|
+
purpose with or without fee is hereby granted.
|
|
38
|
+
|
|
39
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
40
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
41
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
42
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
43
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
44
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
45
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
46
|
+
***************************************************************************** */
|
|
47
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
51
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
52
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
53
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
54
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
55
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
56
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
61
|
+
var e = new Error(message);
|
|
62
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
function apiLoader (str) {
|
|
66
|
+
return `import {
|
|
67
|
+
useAddToFavorites,
|
|
68
|
+
useDidHide,
|
|
69
|
+
useDidShow,
|
|
70
|
+
useError,
|
|
71
|
+
useLaunch,
|
|
72
|
+
useLoad,
|
|
73
|
+
useOptionMenuClick,
|
|
74
|
+
usePageNotFound,
|
|
75
|
+
usePageScroll,
|
|
76
|
+
usePullDownRefresh,
|
|
77
|
+
usePullIntercept,
|
|
78
|
+
useReachBottom,
|
|
79
|
+
useReady,
|
|
80
|
+
useResize,
|
|
81
|
+
useRouter,
|
|
82
|
+
useSaveExitState,
|
|
83
|
+
useShareAppMessage,
|
|
84
|
+
useShareTimeline,
|
|
85
|
+
useTabItemTap,
|
|
86
|
+
useTitleClick,
|
|
87
|
+
useScope,
|
|
88
|
+
useUnhandledRejection,
|
|
89
|
+
useUnload
|
|
90
|
+
} from '@tarojs/plugin-framework-solid/dist/runtime'
|
|
91
|
+
${str}
|
|
92
|
+
|
|
93
|
+
taro.useAddToFavorites = useAddToFavorites
|
|
94
|
+
taro.useDidHide = useDidHide
|
|
95
|
+
taro.useDidShow = useDidShow
|
|
96
|
+
taro.useError = useError
|
|
97
|
+
taro.useLaunch = useLaunch
|
|
98
|
+
taro.useLoad = useLoad
|
|
99
|
+
taro.useOptionMenuClick = useOptionMenuClick
|
|
100
|
+
taro.usePageNotFound = usePageNotFound
|
|
101
|
+
taro.usePageScroll = usePageScroll
|
|
102
|
+
taro.usePullDownRefresh = usePullDownRefresh
|
|
103
|
+
taro.usePullIntercept = usePullIntercept
|
|
104
|
+
taro.useReachBottom = useReachBottom
|
|
105
|
+
taro.useReady = useReady
|
|
106
|
+
taro.useResize = useResize
|
|
107
|
+
taro.useRouter = useRouter
|
|
108
|
+
taro.useSaveExitState = useSaveExitState
|
|
109
|
+
taro.useShareAppMessage = useShareAppMessage
|
|
110
|
+
taro.useShareTimeline = useShareTimeline
|
|
111
|
+
taro.useTabItemTap = useTabItemTap
|
|
112
|
+
taro.useTitleClick = useTitleClick
|
|
113
|
+
taro.useScope = useScope
|
|
114
|
+
taro.useUnhandledRejection = useUnhandledRejection
|
|
115
|
+
taro.useUnload = useUnload
|
|
116
|
+
|
|
117
|
+
export {
|
|
118
|
+
useAddToFavorites,
|
|
119
|
+
useDidHide,
|
|
120
|
+
useDidShow,
|
|
121
|
+
useError,
|
|
122
|
+
useLaunch,
|
|
123
|
+
useLoad,
|
|
124
|
+
useOptionMenuClick,
|
|
125
|
+
usePageNotFound,
|
|
126
|
+
usePageScroll,
|
|
127
|
+
usePullDownRefresh,
|
|
128
|
+
usePullIntercept,
|
|
129
|
+
useReachBottom,
|
|
130
|
+
useReady,
|
|
131
|
+
useResize,
|
|
132
|
+
useRouter,
|
|
133
|
+
useSaveExitState,
|
|
134
|
+
useShareAppMessage,
|
|
135
|
+
useShareTimeline,
|
|
136
|
+
useTabItemTap,
|
|
137
|
+
useTitleClick,
|
|
138
|
+
useScope,
|
|
139
|
+
useUnhandledRejection,
|
|
140
|
+
useUnload
|
|
141
|
+
}
|
|
142
|
+
`;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function addConfig(source) {
|
|
146
|
+
const configsMap = {
|
|
147
|
+
enableShareAppMessage: ['onShareAppMessage', 'useShareAppMessage'],
|
|
148
|
+
enableShareTimeline: ['onShareTimeline', 'useShareTimeline']
|
|
149
|
+
};
|
|
150
|
+
const ast = acorn__namespace.parse(source, {
|
|
151
|
+
ecmaVersion: 'latest',
|
|
152
|
+
sourceType: 'module'
|
|
153
|
+
});
|
|
154
|
+
const additionConfig = {};
|
|
155
|
+
function check(name) {
|
|
156
|
+
Object.keys(configsMap).forEach(configName => {
|
|
157
|
+
const apis = configsMap[configName];
|
|
158
|
+
if (apis.includes(name)) {
|
|
159
|
+
additionConfig[configName] = true;
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
walk__namespace.simple(ast, {
|
|
164
|
+
FunctionExpression(node) {
|
|
165
|
+
if (!node.id || !node.id.name)
|
|
166
|
+
return;
|
|
167
|
+
check(node.id.name);
|
|
168
|
+
},
|
|
169
|
+
FunctionDeclaration(node) {
|
|
170
|
+
if (!node.id || !node.id.name)
|
|
171
|
+
return;
|
|
172
|
+
check(node.id.name);
|
|
173
|
+
},
|
|
174
|
+
CallExpression(node) {
|
|
175
|
+
const { callee } = node;
|
|
176
|
+
if (callee.type === 'Identifier') {
|
|
177
|
+
check(callee.name);
|
|
178
|
+
}
|
|
179
|
+
else if (callee.type === 'MemberExpression') {
|
|
180
|
+
if (callee.property.type === 'Identifier') {
|
|
181
|
+
check(callee.property.name);
|
|
182
|
+
}
|
|
183
|
+
else if (callee.property.type === 'Literal') {
|
|
184
|
+
check(callee.property.value);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
node.arguments.forEach(item => {
|
|
188
|
+
if (item.type === 'Literal' && item.value) {
|
|
189
|
+
check(item.value);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
return additionConfig;
|
|
195
|
+
}
|
|
196
|
+
function getLoaderMeta() {
|
|
197
|
+
const loaderMeta = {
|
|
198
|
+
importFrameworkStatement: '',
|
|
199
|
+
mockAppStatement: `
|
|
200
|
+
function App(props) {
|
|
201
|
+
return null
|
|
202
|
+
}
|
|
203
|
+
`,
|
|
204
|
+
frameworkArgs: 'config',
|
|
205
|
+
creator: 'createSolidApp',
|
|
206
|
+
creatorLocation: '@tarojs/plugin-framework-solid/dist/runtime',
|
|
207
|
+
importFrameworkName: '',
|
|
208
|
+
extraImportForWeb: '',
|
|
209
|
+
execBeforeCreateWebApp: '',
|
|
210
|
+
modifyConfig(config, source) {
|
|
211
|
+
Object.assign(config, addConfig(source));
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
return loaderMeta;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function h5iVitePlugin(ctx) {
|
|
218
|
+
return [
|
|
219
|
+
injectLoaderMeta$2(ctx),
|
|
220
|
+
setTaroApi(),
|
|
221
|
+
];
|
|
222
|
+
}
|
|
223
|
+
function injectLoaderMeta$2(ctx) {
|
|
224
|
+
function customizer(object = '', sources = '') {
|
|
225
|
+
if ([object, sources].every(e => typeof e === 'string'))
|
|
226
|
+
return object + sources;
|
|
227
|
+
}
|
|
228
|
+
const { runnerUtils } = ctx;
|
|
229
|
+
const { getViteH5CompilerContext } = runnerUtils;
|
|
230
|
+
return {
|
|
231
|
+
name: 'taro-solid:loader-meta',
|
|
232
|
+
buildStart() {
|
|
233
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
234
|
+
const viteCompilerContext = yield getViteH5CompilerContext(this);
|
|
235
|
+
if (viteCompilerContext) {
|
|
236
|
+
viteCompilerContext.loaderMeta = lodash.mergeWith(getLoaderMeta(), viteCompilerContext.loaderMeta, customizer);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
function setTaroApi() {
|
|
243
|
+
// dev 环境通过 esbuild 来做; pro 环境通过 rollup load 钩子来做;因为生产环境不会走 esbuild
|
|
244
|
+
return {
|
|
245
|
+
name: 'taro-solid:process-import-taro',
|
|
246
|
+
enforce: 'pre',
|
|
247
|
+
config: () => ({
|
|
248
|
+
optimizeDeps: {
|
|
249
|
+
esbuildOptions: {
|
|
250
|
+
plugins: [
|
|
251
|
+
{
|
|
252
|
+
name: 'taro:solid-api',
|
|
253
|
+
setup(build) {
|
|
254
|
+
build.onLoad({ filter: helper.REG_TARO_H5_RUNTIME_API }, (args) => __awaiter(this, void 0, void 0, function* () {
|
|
255
|
+
const input = yield helper.fs.readFile(args.path, 'utf8');
|
|
256
|
+
return {
|
|
257
|
+
contents: apiLoader(input + '\n' + 'const taro = Taro__default\n')
|
|
258
|
+
};
|
|
259
|
+
}));
|
|
260
|
+
},
|
|
261
|
+
}
|
|
262
|
+
]
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
}),
|
|
266
|
+
load(id) {
|
|
267
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
268
|
+
if (process.env.NODE_ENV === 'production' && helper.REG_TARO_H5_RUNTIME_API.test(id)) {
|
|
269
|
+
try {
|
|
270
|
+
const input = yield helper.fs.readFile(id, 'utf8');
|
|
271
|
+
return apiLoader(input + '\n' + 'const taro = Taro__default\n');
|
|
272
|
+
}
|
|
273
|
+
catch (_) {
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function harmonyVitePlugin(ctx) {
|
|
283
|
+
return [
|
|
284
|
+
injectLoaderMeta$1(ctx),
|
|
285
|
+
aliasPlugin$1(),
|
|
286
|
+
];
|
|
287
|
+
}
|
|
288
|
+
function injectLoaderMeta$1(ctx) {
|
|
289
|
+
return {
|
|
290
|
+
name: 'taro-solid:loader-meta',
|
|
291
|
+
buildStart() {
|
|
292
|
+
const { runnerUtils } = ctx;
|
|
293
|
+
const { getViteHarmonyCompilerContext } = runnerUtils;
|
|
294
|
+
const viteCompilerContext = getViteHarmonyCompilerContext(this);
|
|
295
|
+
if (viteCompilerContext) {
|
|
296
|
+
viteCompilerContext.loaderMeta = getLoaderMeta();
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
function aliasPlugin$1() {
|
|
302
|
+
return {
|
|
303
|
+
name: 'taro-solid:alias',
|
|
304
|
+
config() {
|
|
305
|
+
const alias = [
|
|
306
|
+
{ find: 'solid-js/web$', replacement: RECONCILER_NAME },
|
|
307
|
+
{ find: 'react/jsx-runtime', replacement: RECONCILER_NAME },
|
|
308
|
+
];
|
|
309
|
+
return {
|
|
310
|
+
resolve: {
|
|
311
|
+
alias
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function miniVitePlugin(ctx) {
|
|
319
|
+
return [
|
|
320
|
+
injectLoaderMeta(ctx),
|
|
321
|
+
aliasPlugin(),
|
|
322
|
+
];
|
|
323
|
+
}
|
|
324
|
+
function injectLoaderMeta(ctx) {
|
|
325
|
+
return {
|
|
326
|
+
name: 'taro-solid:loader-meta',
|
|
327
|
+
buildStart() {
|
|
328
|
+
const { runnerUtils } = ctx;
|
|
329
|
+
const { getViteMiniCompilerContext } = runnerUtils;
|
|
330
|
+
const viteCompilerContext = getViteMiniCompilerContext(this);
|
|
331
|
+
if (viteCompilerContext) {
|
|
332
|
+
viteCompilerContext.loaderMeta = getLoaderMeta();
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
function aliasPlugin() {
|
|
338
|
+
return {
|
|
339
|
+
name: 'taro-solid:alias',
|
|
340
|
+
config() {
|
|
341
|
+
const alias = [
|
|
342
|
+
{ find: 'solid-js/web$', replacement: RECONCILER_NAME },
|
|
343
|
+
];
|
|
344
|
+
return {
|
|
345
|
+
resolve: {
|
|
346
|
+
alias
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function modifyH5WebpackChain(ctx, chain) {
|
|
354
|
+
var _a;
|
|
355
|
+
setLoader$2(chain);
|
|
356
|
+
setPlugin(chain);
|
|
357
|
+
const { isBuildNativeComp = false } = ((_a = ctx.runOpts) === null || _a === void 0 ? void 0 : _a.options) || {};
|
|
358
|
+
const externals = {};
|
|
359
|
+
if (isBuildNativeComp) {
|
|
360
|
+
chain.merge({
|
|
361
|
+
externalsType: 'umd'
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
chain.merge({
|
|
365
|
+
externals,
|
|
366
|
+
module: {
|
|
367
|
+
rule: {
|
|
368
|
+
'process-import-taro-h5': {
|
|
369
|
+
test: helper.REG_TARO_H5,
|
|
370
|
+
loader: require.resolve('./api-loader'),
|
|
371
|
+
},
|
|
372
|
+
},
|
|
373
|
+
},
|
|
374
|
+
});
|
|
375
|
+
chain.merge({
|
|
376
|
+
externals,
|
|
377
|
+
module: {
|
|
378
|
+
rule: {
|
|
379
|
+
'process-import-taro-harmony-hybrid': {
|
|
380
|
+
test: /taro-platform-harmony-hybrid[\\/]dist[\\/]api[\\/]apis[\\/]taro/,
|
|
381
|
+
loader: require.resolve('./api-loader')
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
},
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
function setLoader$2(chain) {
|
|
388
|
+
function customizer(object = '', sources = '') {
|
|
389
|
+
if ([object, sources].every((e) => typeof e === 'string'))
|
|
390
|
+
return object + sources;
|
|
391
|
+
}
|
|
392
|
+
chain.plugin('mainPlugin').tap((args) => {
|
|
393
|
+
args[0].loaderMeta = lodash.mergeWith(getLoaderMeta(), args[0].loaderMeta, customizer);
|
|
394
|
+
return args;
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
function setPlugin(chain) {
|
|
398
|
+
const mainFields = ['unpkg', ...helper.defaultMainFields];
|
|
399
|
+
const resolveOptions = {
|
|
400
|
+
basedir: process.cwd(),
|
|
401
|
+
mainFields,
|
|
402
|
+
};
|
|
403
|
+
const alias = chain.resolve.alias;
|
|
404
|
+
// Note: 本地 link 调试时,避免 solid 重复打包
|
|
405
|
+
alias.set('solid-js$', helper.resolveSync('solid-js', resolveOptions));
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
function modifyHarmonyWebpackChain(chain) {
|
|
409
|
+
setAlias$1(chain);
|
|
410
|
+
setLoader$1(chain);
|
|
411
|
+
}
|
|
412
|
+
function setAlias$1(chain) {
|
|
413
|
+
const alias = chain.resolve.alias;
|
|
414
|
+
alias.set('solid-js/web$', RECONCILER_NAME);
|
|
415
|
+
}
|
|
416
|
+
function setLoader$1(chain) {
|
|
417
|
+
chain.plugin('mainPlugin').tap((args) => {
|
|
418
|
+
args[0].loaderMeta = getLoaderMeta();
|
|
419
|
+
return args;
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function modifyMiniWebpackChain(chain) {
|
|
424
|
+
setAlias(chain);
|
|
425
|
+
setLoader(chain);
|
|
426
|
+
}
|
|
427
|
+
function setAlias(chain) {
|
|
428
|
+
const alias = chain.resolve.alias;
|
|
429
|
+
const mainFields = ['unpkg', ...helper.defaultMainFields];
|
|
430
|
+
const resolveOptions = {
|
|
431
|
+
basedir: process.cwd(),
|
|
432
|
+
mainFields,
|
|
433
|
+
};
|
|
434
|
+
alias.set('solid-js/web$', RECONCILER_NAME);
|
|
435
|
+
// Note: 本地 link 调试时,避免 solid 重复打包
|
|
436
|
+
alias.set('solid-js$', helper.resolveSync('solid-js', resolveOptions));
|
|
437
|
+
}
|
|
438
|
+
function setLoader(chain) {
|
|
439
|
+
chain.plugin('miniPlugin')
|
|
440
|
+
.tap(args => {
|
|
441
|
+
args[0].loaderMeta = getLoaderMeta();
|
|
442
|
+
return args;
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
var index = (ctx) => {
|
|
447
|
+
const { framework } = ctx.initialConfig;
|
|
448
|
+
if (framework !== 'solid')
|
|
449
|
+
return;
|
|
450
|
+
ctx.modifyWebpackChain(({ chain }) => {
|
|
451
|
+
chain.plugin('definePlugin').tap((args) => {
|
|
452
|
+
const config = args[0];
|
|
453
|
+
config.__TARO_FRAMEWORK__ = `"${framework}"`;
|
|
454
|
+
return args;
|
|
455
|
+
});
|
|
456
|
+
if (process.env.TARO_PLATFORM === 'web') {
|
|
457
|
+
// H5
|
|
458
|
+
modifyH5WebpackChain(ctx, chain);
|
|
459
|
+
}
|
|
460
|
+
else if (process.env.TARO_PLATFORM === 'harmony' || process.env.TARO_ENV === 'harmony') {
|
|
461
|
+
// 鸿蒙
|
|
462
|
+
modifyHarmonyWebpackChain(chain);
|
|
463
|
+
}
|
|
464
|
+
else {
|
|
465
|
+
// 小程序
|
|
466
|
+
modifyMiniWebpackChain(chain);
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
ctx.modifyRunnerOpts(({ opts }) => {
|
|
470
|
+
if (!(opts === null || opts === void 0 ? void 0 : opts.compiler))
|
|
471
|
+
return;
|
|
472
|
+
if (shared.isString(opts.compiler)) {
|
|
473
|
+
opts.compiler = {
|
|
474
|
+
type: opts.compiler,
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
const { compiler } = opts;
|
|
478
|
+
if (compiler.type === 'webpack5') {
|
|
479
|
+
// 提供给 webpack5 依赖预编译收集器的第三方依赖
|
|
480
|
+
const deps = ['@tarojs/plugin-framework-solid/dist/runtime'];
|
|
481
|
+
compiler.prebundle || (compiler.prebundle = {});
|
|
482
|
+
const prebundleOptions = compiler.prebundle;
|
|
483
|
+
prebundleOptions.include || (prebundleOptions.include = []);
|
|
484
|
+
prebundleOptions.include = prebundleOptions.include.concat(deps);
|
|
485
|
+
const taroSolidPlugin = {
|
|
486
|
+
name: 'taroSolidPlugin',
|
|
487
|
+
setup(build) {
|
|
488
|
+
build.onLoad({ filter: helper.REG_TARO_H5 }, ({ path }) => {
|
|
489
|
+
const content = helper.fs.readFileSync(path).toString();
|
|
490
|
+
return {
|
|
491
|
+
contents: require('./api-loader')(content),
|
|
492
|
+
};
|
|
493
|
+
});
|
|
494
|
+
build.onLoad({ filter: /taro-platform-harmony-hybrid[\\/]dist[\\/]api[\\/]apis[\\/]taro/ }, ({ path }) => {
|
|
495
|
+
const content = helper.fs.readFileSync(path).toString();
|
|
496
|
+
return {
|
|
497
|
+
contents: require('./api-loader')(content)
|
|
498
|
+
};
|
|
499
|
+
});
|
|
500
|
+
},
|
|
501
|
+
};
|
|
502
|
+
prebundleOptions.esbuild || (prebundleOptions.esbuild = {});
|
|
503
|
+
const esbuildConfig = prebundleOptions.esbuild;
|
|
504
|
+
esbuildConfig.plugins || (esbuildConfig.plugins = []);
|
|
505
|
+
esbuildConfig.plugins.push(taroSolidPlugin);
|
|
506
|
+
}
|
|
507
|
+
else if (compiler.type === 'vite') {
|
|
508
|
+
const solidPlugin = require('vite-plugin-solid');
|
|
509
|
+
compiler.vitePlugins || (compiler.vitePlugins = []);
|
|
510
|
+
const solidOptions = {};
|
|
511
|
+
if (process.env.TARO_PLATFORM === 'web') {
|
|
512
|
+
// H5
|
|
513
|
+
compiler.vitePlugins.push(...h5iVitePlugin(ctx));
|
|
514
|
+
}
|
|
515
|
+
else if (process.env.TARO_PLATFORM === 'harmony' || process.env.TARO_ENV === 'harmony') {
|
|
516
|
+
// 鸿蒙
|
|
517
|
+
compiler.vitePlugins.push(harmonyVitePlugin(ctx));
|
|
518
|
+
}
|
|
519
|
+
else {
|
|
520
|
+
Object.assign(solidOptions, {
|
|
521
|
+
moduleName: RECONCILER_NAME,
|
|
522
|
+
generate: 'universal',
|
|
523
|
+
uniqueTransform: true,
|
|
524
|
+
});
|
|
525
|
+
// 小程序
|
|
526
|
+
compiler.vitePlugins.push(miniVitePlugin(ctx));
|
|
527
|
+
}
|
|
528
|
+
// @TODO vite的插件需要内部删除babel-preset-solid
|
|
529
|
+
compiler.vitePlugins.unshift(solidPlugin({
|
|
530
|
+
babel: {
|
|
531
|
+
presets: [
|
|
532
|
+
[
|
|
533
|
+
require('babel-plugin-transform-solid-jsx'),
|
|
534
|
+
solidOptions
|
|
535
|
+
],
|
|
536
|
+
],
|
|
537
|
+
},
|
|
538
|
+
}));
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
// 映射、收集使用到的小程序组件
|
|
542
|
+
ctx.onParseCreateElement(({ nodeName, componentConfig }) => {
|
|
543
|
+
if (shared.capitalize(shared.toCamelCase(nodeName)) in shared.internalComponents) {
|
|
544
|
+
componentConfig.includes.add(nodeName);
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
};
|
|
548
|
+
|
|
549
|
+
exports.default = index;
|
|
550
|
+
//# sourceMappingURL=index.js.map
|