@tarojs/plugin-framework-react 4.0.0-alpha.0 → 4.0.0-alpha.10
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/LICENSE +11 -4
- package/dist/api-loader.js.map +1 -1
- package/dist/index.js +147 -99
- package/dist/index.js.map +1 -1
- package/dist/runtime.js +76 -44
- package/dist/runtime.js.map +1 -1
- package/package.json +37 -33
package/LICENSE
CHANGED
|
@@ -154,7 +154,14 @@ See `/LICENSE` for details of the license.
|
|
|
154
154
|
|
|
155
155
|
==================
|
|
156
156
|
|
|
157
|
-
MIT (
|
|
158
|
-
The following files embed [
|
|
159
|
-
`/packages/taro-components
|
|
160
|
-
See `/LICENSE` for details of the license.
|
|
157
|
+
MIT (weui):
|
|
158
|
+
The following files embed [weui](https://github.com/Tencent/weui) MIT:
|
|
159
|
+
`/packages/taro-components/src/components/*.scss`
|
|
160
|
+
See `/LICENSE.txt` for details of the license.
|
|
161
|
+
|
|
162
|
+
==================
|
|
163
|
+
|
|
164
|
+
Apache-2.0 (intersection-observer):
|
|
165
|
+
The following files embed [intersection-observer](https://github.com/GoogleChromeLabs/intersection-observer) Apache-2.0:
|
|
166
|
+
`/packages/taro-api/src/polyfill/intersection-observer.ts`
|
|
167
|
+
See `/LICENSE.txt` for details of the license.
|
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: 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-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.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;
|
|
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-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.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
CHANGED
|
@@ -4,58 +4,32 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var helper = require('@tarojs/helper');
|
|
6
6
|
var shared = require('@tarojs/shared');
|
|
7
|
+
var tslib = require('tslib');
|
|
7
8
|
var lodash = require('lodash');
|
|
8
9
|
var acorn = require('acorn');
|
|
9
10
|
var walk = require('acorn-walk');
|
|
10
11
|
var path = require('node:path');
|
|
11
12
|
|
|
12
13
|
function _interopNamespaceDefault(e) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
});
|
|
22
|
-
}
|
|
14
|
+
var n = Object.create(null);
|
|
15
|
+
if (e) {
|
|
16
|
+
Object.keys(e).forEach(function (k) {
|
|
17
|
+
if (k !== 'default') {
|
|
18
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
19
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () { return e[k]; }
|
|
23
22
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
n.default = e;
|
|
27
|
+
return Object.freeze(n);
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
var acorn__namespace = /*#__PURE__*/_interopNamespaceDefault(acorn);
|
|
30
31
|
var walk__namespace = /*#__PURE__*/_interopNamespaceDefault(walk);
|
|
31
32
|
|
|
32
|
-
/******************************************************************************
|
|
33
|
-
Copyright (c) Microsoft Corporation.
|
|
34
|
-
|
|
35
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
36
|
-
purpose with or without fee is hereby granted.
|
|
37
|
-
|
|
38
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
39
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
40
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
41
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
42
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
43
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
44
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
45
|
-
***************************************************************************** */
|
|
46
|
-
/* global Reflect, Promise */
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
50
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
51
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
52
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
53
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
54
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
55
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
33
|
function apiLoader (str) {
|
|
60
34
|
return `import {
|
|
61
35
|
useAddToFavorites,
|
|
@@ -187,20 +161,6 @@ function addConfig(source) {
|
|
|
187
161
|
});
|
|
188
162
|
return additionConfig;
|
|
189
163
|
}
|
|
190
|
-
const nervMeta = {
|
|
191
|
-
importFrameworkStatement: `
|
|
192
|
-
import Nerv from 'nervjs';
|
|
193
|
-
`,
|
|
194
|
-
mockAppStatement: `
|
|
195
|
-
class App extends Nerv.Component {
|
|
196
|
-
render () {
|
|
197
|
-
return this.props.children
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
`,
|
|
201
|
-
frameworkArgs: 'Nerv, Nerv, config',
|
|
202
|
-
importFrameworkName: 'Nerv'
|
|
203
|
-
};
|
|
204
164
|
function getLoaderMeta(framework) {
|
|
205
165
|
const loaderMeta = {
|
|
206
166
|
importFrameworkStatement: `
|
|
@@ -224,10 +184,20 @@ class App extends React.Component {
|
|
|
224
184
|
Object.assign(config, addConfig(source));
|
|
225
185
|
}
|
|
226
186
|
};
|
|
227
|
-
if (framework === '
|
|
228
|
-
Object.assign(loaderMeta,
|
|
187
|
+
if (framework === 'solid') {
|
|
188
|
+
Object.assign(loaderMeta, {
|
|
189
|
+
creator: 'createSolidApp',
|
|
190
|
+
frameworkArgs: 'config',
|
|
191
|
+
importFrameworkStatement: '',
|
|
192
|
+
importFrameworkName: '',
|
|
193
|
+
mockAppStatement: `
|
|
194
|
+
function App(props) {
|
|
195
|
+
return null
|
|
196
|
+
}
|
|
197
|
+
`,
|
|
198
|
+
});
|
|
229
199
|
}
|
|
230
|
-
if (
|
|
200
|
+
if (process.env.TARO_PLATFORM === 'web') {
|
|
231
201
|
if (framework === 'react') {
|
|
232
202
|
const react = require('react');
|
|
233
203
|
const majorVersion = Number((react.version || '18').split('.')[0]);
|
|
@@ -259,7 +229,7 @@ function injectLoaderMeta$2(ctx, framework) {
|
|
|
259
229
|
return {
|
|
260
230
|
name: 'taro-react:loader-meta',
|
|
261
231
|
buildStart() {
|
|
262
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
232
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
263
233
|
const viteCompilerContext = yield getViteH5CompilerContext(this);
|
|
264
234
|
if (viteCompilerContext) {
|
|
265
235
|
viteCompilerContext.loaderMeta = lodash.mergeWith(getLoaderMeta(framework), viteCompilerContext.loaderMeta, customizer);
|
|
@@ -275,13 +245,12 @@ function setTaroApi() {
|
|
|
275
245
|
enforce: 'pre',
|
|
276
246
|
config: () => ({
|
|
277
247
|
optimizeDeps: {
|
|
278
|
-
force: true,
|
|
279
248
|
esbuildOptions: {
|
|
280
249
|
plugins: [
|
|
281
250
|
{
|
|
282
251
|
name: 'taro:react-api',
|
|
283
252
|
setup(build) {
|
|
284
|
-
build.onLoad({ filter: helper.REG_TARO_H5_RUNTIME_API }, (args) => __awaiter(this, void 0, void 0, function* () {
|
|
253
|
+
build.onLoad({ filter: helper.REG_TARO_H5_RUNTIME_API }, (args) => tslib.__awaiter(this, void 0, void 0, function* () {
|
|
285
254
|
const input = yield helper.fs.readFile(args.path, 'utf8');
|
|
286
255
|
return {
|
|
287
256
|
contents: apiLoader(input + '\n' + 'const taro = Taro__default\n')
|
|
@@ -294,7 +263,7 @@ function setTaroApi() {
|
|
|
294
263
|
},
|
|
295
264
|
}),
|
|
296
265
|
load(id) {
|
|
297
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
266
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
298
267
|
if (process.env.NODE_ENV === 'production' && helper.REG_TARO_H5_RUNTIME_API.test(id)) {
|
|
299
268
|
try {
|
|
300
269
|
const input = yield helper.fs.readFile(id, 'utf8');
|
|
@@ -317,7 +286,7 @@ function esbuildExclude(framework) {
|
|
|
317
286
|
enforce: 'pre',
|
|
318
287
|
config: () => ({
|
|
319
288
|
optimizeDeps: {
|
|
320
|
-
exclude: ['react', 'preact']
|
|
289
|
+
exclude: ['react', 'preact', 'solid-js']
|
|
321
290
|
}
|
|
322
291
|
})
|
|
323
292
|
};
|
|
@@ -349,20 +318,20 @@ function aliasPlugin$1(ctx, framework) {
|
|
|
349
318
|
config(config) {
|
|
350
319
|
var _a;
|
|
351
320
|
const alias = [
|
|
352
|
-
{ find: /react-dom$/, replacement: '@tarojs/react' }
|
|
321
|
+
{ find: /react-dom$/, replacement: '@tarojs/react' },
|
|
353
322
|
];
|
|
323
|
+
const mainFields = ['unpkg', ...helper.defaultMainFields];
|
|
324
|
+
const resolveOptions = {
|
|
325
|
+
basedir: process.cwd(),
|
|
326
|
+
mainFields,
|
|
327
|
+
};
|
|
354
328
|
const isProd = config.mode === 'production';
|
|
355
329
|
// TODO:harmony 目前会导致部分包用 production 版本,部分用 development 版本,导致许多 api 报错
|
|
356
330
|
const isHarmony = ctx.runOpts.options.platform === 'harmony';
|
|
357
331
|
if (!isProd && ((_a = ctx.initialConfig.harmony) === null || _a === void 0 ? void 0 : _a.debugReact) !== true && !isHarmony) {
|
|
358
|
-
// 不是生产环境,且没有设置 debugReact,则使用压缩版本的 react 依赖,减少体积
|
|
359
|
-
alias.push({ find: /react-reconciler$/, replacement: 'react-reconciler/cjs/react-reconciler.production.min.js' });
|
|
360
|
-
alias.push({ find: /react$/, replacement: 'react/cjs/react.production.min.js' });
|
|
361
|
-
alias.push({ find: /scheduler$/, replacement: 'scheduler/cjs/scheduler.production.min.js' });
|
|
362
|
-
alias.push({ find: /react\/jsx-runtime$/, replacement: 'react/cjs/react-jsx-runtime.production.min.js' });
|
|
363
332
|
// 在React18中,使用了exports字段约定了模块暴露路径,其中并未暴露 ./cjs/ 。这将使上面的alias在编译时报错。相当的tricky。
|
|
364
333
|
// Why writeJson? prebundle will load package.json via readFile to check exports property.
|
|
365
|
-
const reactPkgPath =
|
|
334
|
+
const reactPkgPath = helper.resolveSync('react/package.json', resolveOptions);
|
|
366
335
|
if (reactPkgPath) {
|
|
367
336
|
const reactPkg = require('react/package.json');
|
|
368
337
|
const reactVersion = (reactPkg.version || '');
|
|
@@ -382,6 +351,23 @@ function aliasPlugin$1(ctx, framework) {
|
|
|
382
351
|
}
|
|
383
352
|
};
|
|
384
353
|
}
|
|
354
|
+
else if (framework === 'solid') {
|
|
355
|
+
return {
|
|
356
|
+
name: 'taro-solid:alias',
|
|
357
|
+
config() {
|
|
358
|
+
const reconcilerName = '@tarojs/plugin-framework-react/dist/reconciler';
|
|
359
|
+
const alias = [
|
|
360
|
+
{ find: 'solid-js/web', replacement: reconcilerName },
|
|
361
|
+
{ find: 'react/jsx-runtime', replacement: reconcilerName },
|
|
362
|
+
];
|
|
363
|
+
return {
|
|
364
|
+
resolve: {
|
|
365
|
+
alias
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
}
|
|
385
371
|
return [];
|
|
386
372
|
}
|
|
387
373
|
|
|
@@ -413,6 +399,11 @@ function aliasPlugin(ctx, framework) {
|
|
|
413
399
|
const alias = [
|
|
414
400
|
{ find: /react-dom$/, replacement: '@tarojs/react' }
|
|
415
401
|
];
|
|
402
|
+
const mainFields = ['unpkg', ...helper.defaultMainFields];
|
|
403
|
+
const resolveOptions = {
|
|
404
|
+
basedir: process.cwd(),
|
|
405
|
+
mainFields,
|
|
406
|
+
};
|
|
416
407
|
const isProd = config.mode === 'production';
|
|
417
408
|
// TODO:harmony 目前会导致部分包用 production 版本,部分用 development 版本,导致许多 api 报错
|
|
418
409
|
const isHarmony = ctx.runOpts.options.platform === 'harmony';
|
|
@@ -424,7 +415,7 @@ function aliasPlugin(ctx, framework) {
|
|
|
424
415
|
alias.push({ find: /react\/jsx-runtime$/, replacement: 'react/cjs/react-jsx-runtime.production.min.js' });
|
|
425
416
|
// 在React18中,使用了exports字段约定了模块暴露路径,其中并未暴露 ./cjs/ 。这将使上面的alias在编译时报错。相当的tricky。
|
|
426
417
|
// Why writeJson? prebundle will load package.json via readFile to check exports property.
|
|
427
|
-
const reactPkgPath =
|
|
418
|
+
const reactPkgPath = helper.resolveSync('react/package.json', resolveOptions);
|
|
428
419
|
if (reactPkgPath) {
|
|
429
420
|
const reactPkg = require('react/package.json');
|
|
430
421
|
const reactVersion = (reactPkg.version || '');
|
|
@@ -444,6 +435,23 @@ function aliasPlugin(ctx, framework) {
|
|
|
444
435
|
}
|
|
445
436
|
};
|
|
446
437
|
}
|
|
438
|
+
else if (framework === 'solid') {
|
|
439
|
+
return {
|
|
440
|
+
name: 'taro-solid:alias',
|
|
441
|
+
config() {
|
|
442
|
+
const reconcilerName = '@tarojs/plugin-framework-react/dist/reconciler';
|
|
443
|
+
const alias = [
|
|
444
|
+
{ find: 'solid-js/web', replacement: reconcilerName },
|
|
445
|
+
{ find: 'react/jsx-runtime', replacement: reconcilerName },
|
|
446
|
+
];
|
|
447
|
+
return {
|
|
448
|
+
resolve: {
|
|
449
|
+
alias
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
}
|
|
447
455
|
return [];
|
|
448
456
|
}
|
|
449
457
|
|
|
@@ -455,17 +463,30 @@ function modifyH5WebpackChain(ctx, framework, chain) {
|
|
|
455
463
|
const externals = {};
|
|
456
464
|
if (isBuildNativeComp) {
|
|
457
465
|
// Note: 该模式不支持 prebundle 优化,不必再处理
|
|
458
|
-
externals.react =
|
|
459
|
-
|
|
466
|
+
externals.react = {
|
|
467
|
+
commonjs: 'react',
|
|
468
|
+
commonjs2: 'react',
|
|
469
|
+
amd: 'react',
|
|
470
|
+
root: 'React'
|
|
471
|
+
};
|
|
472
|
+
externals['react-dom'] = {
|
|
473
|
+
commonjs: 'react-dom',
|
|
474
|
+
commonjs2: 'react-dom',
|
|
475
|
+
amd: 'react-dom',
|
|
476
|
+
root: 'ReactDOM'
|
|
477
|
+
};
|
|
460
478
|
if (framework === 'preact') {
|
|
461
479
|
externals.preact = 'preact';
|
|
462
480
|
}
|
|
481
|
+
chain.merge({
|
|
482
|
+
externalsType: 'umd'
|
|
483
|
+
});
|
|
463
484
|
}
|
|
464
485
|
chain.merge({
|
|
465
486
|
externals,
|
|
466
487
|
module: {
|
|
467
488
|
rule: {
|
|
468
|
-
'process-import-taro': {
|
|
489
|
+
'process-import-taro-h5': {
|
|
469
490
|
test: helper.REG_TARO_H5,
|
|
470
491
|
loader: require.resolve('./api-loader'),
|
|
471
492
|
},
|
|
@@ -498,6 +519,24 @@ function setPlugin(ctx, framework, chain) {
|
|
|
498
519
|
chain.plugin('fastRefreshPlugin').use(require('@prefresh/webpack'));
|
|
499
520
|
}
|
|
500
521
|
}
|
|
522
|
+
const mainFields = ['unpkg', ...helper.defaultMainFields];
|
|
523
|
+
const resolveOptions = {
|
|
524
|
+
basedir: process.cwd(),
|
|
525
|
+
mainFields,
|
|
526
|
+
};
|
|
527
|
+
if (framework === 'solid') {
|
|
528
|
+
const reconcilerName = '@tarojs/plugin-framework-react/dist/reconciler';
|
|
529
|
+
const alias = chain.resolve.alias;
|
|
530
|
+
alias.set(reconcilerName, helper.resolveSync('solid-js/web', resolveOptions));
|
|
531
|
+
// Note: 本地 link 调试时,避免 solid 重复打包
|
|
532
|
+
alias.set('solid-js$', helper.resolveSync('solid-js', resolveOptions));
|
|
533
|
+
}
|
|
534
|
+
else if (framework === 'react') {
|
|
535
|
+
const alias = chain.resolve.alias;
|
|
536
|
+
// Note: 本地 link 调试时,避免 react 重复打包
|
|
537
|
+
alias.set('react$', helper.resolveSync('react', resolveOptions));
|
|
538
|
+
alias.set('react-dom$', helper.resolveSync('react-dom', resolveOptions));
|
|
539
|
+
}
|
|
501
540
|
}
|
|
502
541
|
|
|
503
542
|
function modifyHarmonyWebpackChain(ctx, framework, chain) {
|
|
@@ -508,6 +547,11 @@ function setAlias$2(ctx, framework, chain) {
|
|
|
508
547
|
var _a;
|
|
509
548
|
const config = ctx.initialConfig;
|
|
510
549
|
const alias = chain.resolve.alias;
|
|
550
|
+
const mainFields = ['unpkg', ...helper.defaultMainFields];
|
|
551
|
+
const resolveOptions = {
|
|
552
|
+
basedir: process.cwd(),
|
|
553
|
+
mainFields,
|
|
554
|
+
};
|
|
511
555
|
if (framework === 'react') {
|
|
512
556
|
alias.set('react-dom$', '@tarojs/react');
|
|
513
557
|
alias.set('react-dom/client$', '@tarojs/react');
|
|
@@ -516,14 +560,14 @@ function setAlias$2(ctx, framework, chain) {
|
|
|
516
560
|
if (!isProd && ((_a = config.harmony) === null || _a === void 0 ? void 0 : _a.debugReact) !== true) {
|
|
517
561
|
// 不是生产环境,且没有设置 debugReact,则使用压缩版本的 react 依赖,减少体积
|
|
518
562
|
// 兼容pnpm workspace
|
|
519
|
-
const reactModulePath =
|
|
563
|
+
const reactModulePath = helper.resolveSync('react', resolveOptions);
|
|
520
564
|
const newFilePath = path.join(path.dirname(reactModulePath), 'cjs', 'react.production.min.js');
|
|
521
565
|
alias.set('react-reconciler$', 'react-reconciler/cjs/react-reconciler.production.min.js');
|
|
522
566
|
alias.set('react$', newFilePath);
|
|
523
567
|
alias.set('react/jsx-runtime$', 'react/cjs/react-jsx-runtime.production.min.js');
|
|
524
568
|
// 在React18中,使用了exports字段约定了模块暴露路径,其中并未暴露 ./cjs/ 。这将使上面的alias在编译时报错。相当的tricky。
|
|
525
569
|
// Why writeJson? prebundle will load package.json via readFile to check exports property.
|
|
526
|
-
const reactPkgPath =
|
|
570
|
+
const reactPkgPath = helper.resolveSync('react/package.json', resolveOptions);
|
|
527
571
|
if (reactPkgPath) {
|
|
528
572
|
const reactPkg = require('react/package.json');
|
|
529
573
|
const reactVersion = reactPkg.version || '';
|
|
@@ -536,6 +580,11 @@ function setAlias$2(ctx, framework, chain) {
|
|
|
536
580
|
}
|
|
537
581
|
}
|
|
538
582
|
}
|
|
583
|
+
else if (framework === 'solid') {
|
|
584
|
+
const reconcilerName = '@tarojs/plugin-framework-react/dist/reconciler';
|
|
585
|
+
alias.set('solid-js/web', reconcilerName);
|
|
586
|
+
alias.set('react/jsx-runtime', reconcilerName);
|
|
587
|
+
}
|
|
539
588
|
}
|
|
540
589
|
function setLoader$1(framework, chain) {
|
|
541
590
|
chain.plugin('mainPlugin').tap((args) => {
|
|
@@ -552,6 +601,11 @@ function setAlias$1(ctx, framework, chain) {
|
|
|
552
601
|
var _a;
|
|
553
602
|
const config = ctx.initialConfig;
|
|
554
603
|
const alias = chain.resolve.alias;
|
|
604
|
+
const mainFields = ['unpkg', ...helper.defaultMainFields];
|
|
605
|
+
const resolveOptions = {
|
|
606
|
+
basedir: process.cwd(),
|
|
607
|
+
mainFields,
|
|
608
|
+
};
|
|
555
609
|
if (framework === 'react') {
|
|
556
610
|
alias.set('react-dom$', '@tarojs/react');
|
|
557
611
|
alias.set('react-dom/client$', '@tarojs/react');
|
|
@@ -560,14 +614,14 @@ function setAlias$1(ctx, framework, chain) {
|
|
|
560
614
|
if (!isProd && ((_a = config.mini) === null || _a === void 0 ? void 0 : _a.debugReact) !== true) {
|
|
561
615
|
// 不是生产环境,且没有设置 debugReact,则使用压缩版本的 react 依赖,减少体积
|
|
562
616
|
// 兼容pnpm workspace
|
|
563
|
-
const reactModulePath =
|
|
617
|
+
const reactModulePath = helper.resolveSync('react', resolveOptions);
|
|
564
618
|
const newFilePath = path.join(path.dirname(reactModulePath), 'cjs', 'react.production.min.js');
|
|
565
619
|
alias.set('react-reconciler$', 'react-reconciler/cjs/react-reconciler.production.min.js');
|
|
566
620
|
alias.set(/^(?!.*mobx-react$).*react$/, newFilePath);
|
|
567
621
|
alias.set('react/jsx-runtime$', 'react/cjs/react-jsx-runtime.production.min.js');
|
|
568
622
|
// 在React18中,使用了exports字段约定了模块暴露路径,其中并未暴露 ./cjs/ 。这将使上面的alias在编译时报错。相当的tricky。
|
|
569
623
|
// Why writeJson? prebundle will load package.json via readFile to check exports property.
|
|
570
|
-
const reactPkgPath =
|
|
624
|
+
const reactPkgPath = helper.resolveSync('react/package.json', resolveOptions);
|
|
571
625
|
if (reactPkgPath) {
|
|
572
626
|
const reactPkg = require('react/package.json');
|
|
573
627
|
const reactVersion = reactPkg.version || '';
|
|
@@ -580,6 +634,12 @@ function setAlias$1(ctx, framework, chain) {
|
|
|
580
634
|
}
|
|
581
635
|
}
|
|
582
636
|
}
|
|
637
|
+
else if (framework === 'solid') {
|
|
638
|
+
const reconcilerName = '@tarojs/plugin-framework-react/dist/reconciler';
|
|
639
|
+
alias.set('solid-js/web', reconcilerName);
|
|
640
|
+
// Note: 本地 link 调试时,避免 solid 重复打包
|
|
641
|
+
alias.set('solid-js$', helper.resolveSync('solid-js', resolveOptions));
|
|
642
|
+
}
|
|
583
643
|
}
|
|
584
644
|
function setLoader(framework, chain) {
|
|
585
645
|
chain.plugin('miniPlugin').tap((args) => {
|
|
@@ -589,7 +649,7 @@ function setLoader(framework, chain) {
|
|
|
589
649
|
}
|
|
590
650
|
|
|
591
651
|
function isReactLike(framework = 'react') {
|
|
592
|
-
return ['react', 'preact', '
|
|
652
|
+
return ['react', 'preact', 'solid'].includes(framework);
|
|
593
653
|
}
|
|
594
654
|
var index = (ctx) => {
|
|
595
655
|
const { framework = 'react' } = ctx.initialConfig;
|
|
@@ -598,12 +658,7 @@ var index = (ctx) => {
|
|
|
598
658
|
ctx.modifyWebpackChain(({ chain }) => {
|
|
599
659
|
// 通用
|
|
600
660
|
setAlias(framework, chain);
|
|
601
|
-
|
|
602
|
-
const config = args[0];
|
|
603
|
-
config.__TARO_FRAMEWORK__ = `"${framework}"`;
|
|
604
|
-
return args;
|
|
605
|
-
});
|
|
606
|
-
if (shared.isWebPlatform()) {
|
|
661
|
+
if (process.env.TARO_PLATFORM === 'web') {
|
|
607
662
|
// H5
|
|
608
663
|
modifyH5WebpackChain(ctx, framework, chain);
|
|
609
664
|
}
|
|
@@ -645,7 +700,7 @@ var index = (ctx) => {
|
|
|
645
700
|
contents: require('./api-loader')(content),
|
|
646
701
|
};
|
|
647
702
|
});
|
|
648
|
-
}
|
|
703
|
+
}
|
|
649
704
|
};
|
|
650
705
|
prebundleOptions.esbuild || (prebundleOptions.esbuild = {});
|
|
651
706
|
const esbuildConfig = prebundleOptions.esbuild;
|
|
@@ -656,7 +711,7 @@ var index = (ctx) => {
|
|
|
656
711
|
compiler.vitePlugins || (compiler.vitePlugins = []);
|
|
657
712
|
compiler.vitePlugins.push(viteCommonPlugin(framework));
|
|
658
713
|
compiler.vitePlugins.push(VitePresetPlugin(framework));
|
|
659
|
-
if (
|
|
714
|
+
if (process.env.TARO_PLATFORM === 'web') {
|
|
660
715
|
// H5
|
|
661
716
|
compiler.vitePlugins.push(h5iVitePlugin(ctx, framework));
|
|
662
717
|
}
|
|
@@ -680,9 +735,8 @@ function setAlias(framework, chain) {
|
|
|
680
735
|
alias.set('react-dom', 'preact/compat');
|
|
681
736
|
alias.set('react/jsx-runtime', 'preact/jsx-runtime');
|
|
682
737
|
break;
|
|
683
|
-
case '
|
|
684
|
-
alias.set('react
|
|
685
|
-
alias.set('react-dom$', 'nervjs');
|
|
738
|
+
case 'solid':
|
|
739
|
+
alias.set('react/jsx-runtime', 'solid-js/h/jsx-runtime');
|
|
686
740
|
break;
|
|
687
741
|
}
|
|
688
742
|
}
|
|
@@ -717,17 +771,11 @@ function viteCommonPlugin(framework) {
|
|
|
717
771
|
{ find: 'react/jsx-runtime', replacement: 'preact/jsx-runtime' },
|
|
718
772
|
]
|
|
719
773
|
: [];
|
|
774
|
+
if (framework === 'solid') {
|
|
775
|
+
const reconcilerName = '@tarojs/plugin-framework-react/dist/reconciler';
|
|
776
|
+
alias.push({ find: 'react/jsx-runtime', replacement: reconcilerName });
|
|
777
|
+
}
|
|
720
778
|
return {
|
|
721
|
-
optimizeDeps: {
|
|
722
|
-
esbuildOptions: {
|
|
723
|
-
define: {
|
|
724
|
-
__TARO_FRAMEWORK__: `"${framework}"`
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
},
|
|
728
|
-
define: {
|
|
729
|
-
__TARO_FRAMEWORK__: `"${framework}"`,
|
|
730
|
-
},
|
|
731
779
|
resolve: {
|
|
732
780
|
alias,
|
|
733
781
|
},
|