@tarojs/plugin-framework-react 4.0.0-canary.9 → 4.0.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/LICENSE CHANGED
@@ -154,15 +154,8 @@ See `/LICENSE` for details of the license.
154
154
 
155
155
  ==================
156
156
 
157
- MIT (stencil-vue2-output-target):
158
- The following files embed [stencil-vue2-output-target](https://github.com/diondree/stencil-vue2-output-target) MIT:
159
- `/packages/taro-components-library-vue2/src/vue-component-lib/utils.ts`
160
- See `/LICENSE` for details of the license.
161
-
162
- ==================
163
-
164
157
  MIT (weui):
165
- The following files embed [stencil-vue2-output-target](https://github.com/Tencent/weui) MIT:
158
+ The following files embed [weui](https://github.com/Tencent/weui) MIT:
166
159
  `/packages/taro-components/src/components/*.scss`
167
160
  See `/LICENSE.txt` for details of the license.
168
161
 
@@ -172,3 +165,10 @@ Apache-2.0 (intersection-observer):
172
165
  The following files embed [intersection-observer](https://github.com/GoogleChromeLabs/intersection-observer) Apache-2.0:
173
166
  `/packages/taro-api/src/polyfill/intersection-observer.ts`
174
167
  See `/LICENSE.txt` for details of the license.
168
+
169
+ ==================
170
+
171
+ MIT (babel-plugin-jsx-dom-expressions):
172
+ The following files embed [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/blob/main/packages/babel-plugin-jsx-dom-expressions) MIT:
173
+ `/packages/babel-plugin-transform-solid-jsx/src/*`
174
+ See `/LICENSE` for details of the license.
@@ -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;IAChC,OAAO,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;EAyBT,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmDJ,CAAC;AACF;;;;"}
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,63 +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
- var n = Object.create(null);
14
- if (e) {
15
- Object.keys(e).forEach(function (k) {
16
- if (k !== 'default') {
17
- var d = Object.getOwnPropertyDescriptor(e, k);
18
- Object.defineProperty(n, k, d.get ? d : {
19
- enumerable: true,
20
- get: function () { return e[k]; }
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
- n.default = e;
26
- return Object.freeze(n);
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, SuppressedError, Symbol */
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
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
60
- var e = new Error(message);
61
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
62
- };
63
-
64
33
  function apiLoader (str) {
65
34
  return `import {
66
35
  useAddToFavorites,
@@ -192,20 +161,6 @@ function addConfig(source) {
192
161
  });
193
162
  return additionConfig;
194
163
  }
195
- const nervMeta = {
196
- importFrameworkStatement: `
197
- import Nerv from 'nervjs';
198
- `,
199
- mockAppStatement: `
200
- class App extends Nerv.Component {
201
- render () {
202
- return this.props.children
203
- }
204
- }
205
- `,
206
- frameworkArgs: 'Nerv, Nerv, config',
207
- importFrameworkName: 'Nerv'
208
- };
209
164
  function getLoaderMeta(framework) {
210
165
  const loaderMeta = {
211
166
  importFrameworkStatement: `
@@ -229,9 +184,6 @@ class App extends React.Component {
229
184
  Object.assign(config, addConfig(source));
230
185
  }
231
186
  };
232
- if (framework === 'nerv') {
233
- Object.assign(loaderMeta, nervMeta);
234
- }
235
187
  if (process.env.TARO_PLATFORM === 'web') {
236
188
  if (framework === 'react') {
237
189
  const react = require('react');
@@ -264,7 +216,7 @@ function injectLoaderMeta$2(ctx, framework) {
264
216
  return {
265
217
  name: 'taro-react:loader-meta',
266
218
  buildStart() {
267
- return __awaiter(this, void 0, void 0, function* () {
219
+ return tslib.__awaiter(this, void 0, void 0, function* () {
268
220
  const viteCompilerContext = yield getViteH5CompilerContext(this);
269
221
  if (viteCompilerContext) {
270
222
  viteCompilerContext.loaderMeta = lodash.mergeWith(getLoaderMeta(framework), viteCompilerContext.loaderMeta, customizer);
@@ -280,13 +232,12 @@ function setTaroApi() {
280
232
  enforce: 'pre',
281
233
  config: () => ({
282
234
  optimizeDeps: {
283
- force: true,
284
235
  esbuildOptions: {
285
236
  plugins: [
286
237
  {
287
238
  name: 'taro:react-api',
288
239
  setup(build) {
289
- build.onLoad({ filter: helper.REG_TARO_H5_RUNTIME_API }, (args) => __awaiter(this, void 0, void 0, function* () {
240
+ build.onLoad({ filter: helper.REG_TARO_H5_RUNTIME_API }, (args) => tslib.__awaiter(this, void 0, void 0, function* () {
290
241
  const input = yield helper.fs.readFile(args.path, 'utf8');
291
242
  return {
292
243
  contents: apiLoader(input + '\n' + 'const taro = Taro__default\n')
@@ -299,7 +250,7 @@ function setTaroApi() {
299
250
  },
300
251
  }),
301
252
  load(id) {
302
- return __awaiter(this, void 0, void 0, function* () {
253
+ return tslib.__awaiter(this, void 0, void 0, function* () {
303
254
  if (process.env.NODE_ENV === 'production' && helper.REG_TARO_H5_RUNTIME_API.test(id)) {
304
255
  try {
305
256
  const input = yield helper.fs.readFile(id, 'utf8');
@@ -342,7 +293,8 @@ function injectLoaderMeta$1(ctx, framework) {
342
293
  const { getViteHarmonyCompilerContext } = runnerUtils;
343
294
  const viteCompilerContext = getViteHarmonyCompilerContext(this);
344
295
  if (viteCompilerContext) {
345
- viteCompilerContext.loaderMeta = getLoaderMeta(framework);
296
+ viteCompilerContext.loaderMeta || (viteCompilerContext.loaderMeta = {});
297
+ Object.assign(viteCompilerContext.loaderMeta, getLoaderMeta(framework));
346
298
  }
347
299
  }
348
300
  };
@@ -354,20 +306,21 @@ function aliasPlugin$1(ctx, framework) {
354
306
  config(config) {
355
307
  var _a;
356
308
  const alias = [
357
- { find: /react-dom$/, replacement: '@tarojs/react' }
309
+ { find: /react-dom$/, replacement: '@tarojs/react' },
310
+ { find: /react-dom\/client$/, replacement: '@tarojs/react' },
358
311
  ];
312
+ const mainFields = ['unpkg', ...helper.defaultMainFields];
313
+ const resolveOptions = {
314
+ basedir: process.cwd(),
315
+ mainFields,
316
+ };
359
317
  const isProd = config.mode === 'production';
360
318
  // TODO:harmony 目前会导致部分包用 production 版本,部分用 development 版本,导致许多 api 报错
361
319
  const isHarmony = ctx.runOpts.options.platform === 'harmony';
362
320
  if (!isProd && ((_a = ctx.initialConfig.harmony) === null || _a === void 0 ? void 0 : _a.debugReact) !== true && !isHarmony) {
363
- // 不是生产环境,且没有设置 debugReact,则使用压缩版本的 react 依赖,减少体积
364
- alias.push({ find: /react-reconciler$/, replacement: 'react-reconciler/cjs/react-reconciler.production.min.js' });
365
- alias.push({ find: /react$/, replacement: 'react/cjs/react.production.min.js' });
366
- alias.push({ find: /scheduler$/, replacement: 'scheduler/cjs/scheduler.production.min.js' });
367
- alias.push({ find: /react\/jsx-runtime$/, replacement: 'react/cjs/react-jsx-runtime.production.min.js' });
368
321
  // 在React18中,使用了exports字段约定了模块暴露路径,其中并未暴露 ./cjs/ 。这将使上面的alias在编译时报错。相当的tricky。
369
322
  // Why writeJson? prebundle will load package.json via readFile to check exports property.
370
- const reactPkgPath = require.resolve('react/package.json', { paths: [process.cwd()] });
323
+ const reactPkgPath = helper.resolveSync('react/package.json', resolveOptions);
371
324
  if (reactPkgPath) {
372
325
  const reactPkg = require('react/package.json');
373
326
  const reactVersion = (reactPkg.version || '');
@@ -404,7 +357,8 @@ function injectLoaderMeta(ctx, framework) {
404
357
  const { getViteMiniCompilerContext } = runnerUtils;
405
358
  const viteCompilerContext = getViteMiniCompilerContext(this);
406
359
  if (viteCompilerContext) {
407
- viteCompilerContext.loaderMeta = getLoaderMeta(framework);
360
+ viteCompilerContext.loaderMeta || (viteCompilerContext.loaderMeta = {});
361
+ Object.assign(viteCompilerContext.loaderMeta, getLoaderMeta(framework));
408
362
  }
409
363
  }
410
364
  };
@@ -416,8 +370,14 @@ function aliasPlugin(ctx, framework) {
416
370
  config(config) {
417
371
  var _a;
418
372
  const alias = [
419
- { find: /react-dom$/, replacement: '@tarojs/react' }
373
+ { find: /react-dom$/, replacement: '@tarojs/react' },
374
+ { find: /react-dom\/client$/, replacement: '@tarojs/react' },
420
375
  ];
376
+ const mainFields = ['unpkg', ...helper.defaultMainFields];
377
+ const resolveOptions = {
378
+ basedir: process.cwd(),
379
+ mainFields,
380
+ };
421
381
  const isProd = config.mode === 'production';
422
382
  // TODO:harmony 目前会导致部分包用 production 版本,部分用 development 版本,导致许多 api 报错
423
383
  const isHarmony = ctx.runOpts.options.platform === 'harmony';
@@ -429,7 +389,7 @@ function aliasPlugin(ctx, framework) {
429
389
  alias.push({ find: /react\/jsx-runtime$/, replacement: 'react/cjs/react-jsx-runtime.production.min.js' });
430
390
  // 在React18中,使用了exports字段约定了模块暴露路径,其中并未暴露 ./cjs/ 。这将使上面的alias在编译时报错。相当的tricky。
431
391
  // Why writeJson? prebundle will load package.json via readFile to check exports property.
432
- const reactPkgPath = require.resolve('react/package.json', { paths: [process.cwd()] });
392
+ const reactPkgPath = helper.resolveSync('react/package.json', resolveOptions);
433
393
  if (reactPkgPath) {
434
394
  const reactPkg = require('react/package.json');
435
395
  const reactVersion = (reactPkg.version || '');
@@ -460,11 +420,24 @@ function modifyH5WebpackChain(ctx, framework, chain) {
460
420
  const externals = {};
461
421
  if (isBuildNativeComp) {
462
422
  // Note: 该模式不支持 prebundle 优化,不必再处理
463
- externals.react = 'React';
464
- externals['react-dom'] = 'ReactDOM';
423
+ externals.react = {
424
+ commonjs: 'react',
425
+ commonjs2: 'react',
426
+ amd: 'react',
427
+ root: 'React'
428
+ };
429
+ externals['react-dom'] = {
430
+ commonjs: 'react-dom',
431
+ commonjs2: 'react-dom',
432
+ amd: 'react-dom',
433
+ root: 'ReactDOM'
434
+ };
465
435
  if (framework === 'preact') {
466
436
  externals.preact = 'preact';
467
437
  }
438
+ chain.merge({
439
+ externalsType: 'umd'
440
+ });
468
441
  }
469
442
  chain.merge({
470
443
  externals,
@@ -477,28 +450,6 @@ function modifyH5WebpackChain(ctx, framework, chain) {
477
450
  },
478
451
  },
479
452
  });
480
- chain.merge({
481
- externals,
482
- module: {
483
- rule: {
484
- 'process-import-taro-harmony-hybrid': {
485
- test: /taro-platform-harmony-hybrid[\\/]dist[\\/]api[\\/]apis[\\/]taro/,
486
- loader: require.resolve('./api-loader')
487
- }
488
- }
489
- },
490
- });
491
- chain.merge({
492
- externals,
493
- module: {
494
- rule: {
495
- 'process-import-taro-harmony-hybrid': {
496
- test: /taro-platform-harmony-hybrid[\\/]dist[\\/]api[\\/]apis[\\/]taro/,
497
- loader: require.resolve('./api-loader')
498
- }
499
- }
500
- },
501
- });
502
453
  }
503
454
  function setLoader$2(framework, chain) {
504
455
  function customizer(object = '', sources = '') {
@@ -525,6 +476,17 @@ function setPlugin(ctx, framework, chain) {
525
476
  chain.plugin('fastRefreshPlugin').use(require('@prefresh/webpack'));
526
477
  }
527
478
  }
479
+ const mainFields = ['unpkg', ...helper.defaultMainFields];
480
+ const resolveOptions = {
481
+ basedir: process.cwd(),
482
+ mainFields,
483
+ };
484
+ if (framework === 'react') {
485
+ const alias = chain.resolve.alias;
486
+ // Note: 本地 link 调试时,避免 react 重复打包
487
+ alias.set('react$', helper.resolveSync('react', resolveOptions));
488
+ alias.set('react-dom$', helper.resolveSync('react-dom', resolveOptions));
489
+ }
528
490
  }
529
491
 
530
492
  function modifyHarmonyWebpackChain(ctx, framework, chain) {
@@ -535,6 +497,11 @@ function setAlias$2(ctx, framework, chain) {
535
497
  var _a;
536
498
  const config = ctx.initialConfig;
537
499
  const alias = chain.resolve.alias;
500
+ const mainFields = ['unpkg', ...helper.defaultMainFields];
501
+ const resolveOptions = {
502
+ basedir: process.cwd(),
503
+ mainFields,
504
+ };
538
505
  if (framework === 'react') {
539
506
  alias.set('react-dom$', '@tarojs/react');
540
507
  alias.set('react-dom/client$', '@tarojs/react');
@@ -543,14 +510,14 @@ function setAlias$2(ctx, framework, chain) {
543
510
  if (!isProd && ((_a = config.harmony) === null || _a === void 0 ? void 0 : _a.debugReact) !== true) {
544
511
  // 不是生产环境,且没有设置 debugReact,则使用压缩版本的 react 依赖,减少体积
545
512
  // 兼容pnpm workspace
546
- const reactModulePath = require.resolve('react', { paths: [process.cwd()] });
513
+ const reactModulePath = helper.resolveSync('react', resolveOptions);
547
514
  const newFilePath = path.join(path.dirname(reactModulePath), 'cjs', 'react.production.min.js');
548
515
  alias.set('react-reconciler$', 'react-reconciler/cjs/react-reconciler.production.min.js');
549
516
  alias.set('react$', newFilePath);
550
517
  alias.set('react/jsx-runtime$', 'react/cjs/react-jsx-runtime.production.min.js');
551
518
  // 在React18中,使用了exports字段约定了模块暴露路径,其中并未暴露 ./cjs/ 。这将使上面的alias在编译时报错。相当的tricky。
552
519
  // Why writeJson? prebundle will load package.json via readFile to check exports property.
553
- const reactPkgPath = require.resolve('react/package.json', { paths: [process.cwd()] });
520
+ const reactPkgPath = helper.resolveSync('react/package.json', resolveOptions);
554
521
  if (reactPkgPath) {
555
522
  const reactPkg = require('react/package.json');
556
523
  const reactVersion = reactPkg.version || '';
@@ -566,7 +533,9 @@ function setAlias$2(ctx, framework, chain) {
566
533
  }
567
534
  function setLoader$1(framework, chain) {
568
535
  chain.plugin('mainPlugin').tap((args) => {
569
- args[0].loaderMeta = getLoaderMeta(framework);
536
+ var _a;
537
+ (_a = args[0]).loaderMeta || (_a.loaderMeta = {});
538
+ Object.assign(args[0].loaderMeta, getLoaderMeta(framework));
570
539
  return args;
571
540
  });
572
541
  }
@@ -579,6 +548,11 @@ function setAlias$1(ctx, framework, chain) {
579
548
  var _a;
580
549
  const config = ctx.initialConfig;
581
550
  const alias = chain.resolve.alias;
551
+ const mainFields = ['unpkg', ...helper.defaultMainFields];
552
+ const resolveOptions = {
553
+ basedir: process.cwd(),
554
+ mainFields,
555
+ };
582
556
  if (framework === 'react') {
583
557
  alias.set('react-dom$', '@tarojs/react');
584
558
  alias.set('react-dom/client$', '@tarojs/react');
@@ -587,14 +561,14 @@ function setAlias$1(ctx, framework, chain) {
587
561
  if (!isProd && ((_a = config.mini) === null || _a === void 0 ? void 0 : _a.debugReact) !== true) {
588
562
  // 不是生产环境,且没有设置 debugReact,则使用压缩版本的 react 依赖,减少体积
589
563
  // 兼容pnpm workspace
590
- const reactModulePath = require.resolve('react', { paths: [process.cwd()] });
564
+ const reactModulePath = helper.resolveSync('react', resolveOptions);
591
565
  const newFilePath = path.join(path.dirname(reactModulePath), 'cjs', 'react.production.min.js');
592
566
  alias.set('react-reconciler$', 'react-reconciler/cjs/react-reconciler.production.min.js');
593
567
  alias.set(/^(?!.*mobx-react$).*react$/, newFilePath);
594
568
  alias.set('react/jsx-runtime$', 'react/cjs/react-jsx-runtime.production.min.js');
595
569
  // 在React18中,使用了exports字段约定了模块暴露路径,其中并未暴露 ./cjs/ 。这将使上面的alias在编译时报错。相当的tricky。
596
570
  // Why writeJson? prebundle will load package.json via readFile to check exports property.
597
- const reactPkgPath = require.resolve('react/package.json', { paths: [process.cwd()] });
571
+ const reactPkgPath = helper.resolveSync('react/package.json', resolveOptions);
598
572
  if (reactPkgPath) {
599
573
  const reactPkg = require('react/package.json');
600
574
  const reactVersion = reactPkg.version || '';
@@ -610,13 +584,15 @@ function setAlias$1(ctx, framework, chain) {
610
584
  }
611
585
  function setLoader(framework, chain) {
612
586
  chain.plugin('miniPlugin').tap((args) => {
613
- args[0].loaderMeta = getLoaderMeta(framework);
587
+ var _a;
588
+ (_a = args[0]).loaderMeta || (_a.loaderMeta = {});
589
+ Object.assign(args[0].loaderMeta, getLoaderMeta(framework));
614
590
  return args;
615
591
  });
616
592
  }
617
593
 
618
594
  function isReactLike(framework = 'react') {
619
- return ['react', 'preact', 'nerv', 'solid'].includes(framework);
595
+ return ['react', 'preact'].includes(framework);
620
596
  }
621
597
  var index = (ctx) => {
622
598
  const { framework = 'react' } = ctx.initialConfig;
@@ -625,11 +601,6 @@ var index = (ctx) => {
625
601
  ctx.modifyWebpackChain(({ chain }) => {
626
602
  // 通用
627
603
  setAlias(framework, chain);
628
- chain.plugin('definePlugin').tap((args) => {
629
- const config = args[0];
630
- config.__TARO_FRAMEWORK__ = `"${framework}"`;
631
- return args;
632
- });
633
604
  if (process.env.TARO_PLATFORM === 'web') {
634
605
  // H5
635
606
  modifyH5WebpackChain(ctx, framework, chain);
@@ -672,13 +643,7 @@ var index = (ctx) => {
672
643
  contents: require('./api-loader')(content),
673
644
  };
674
645
  });
675
- build.onLoad({ filter: /taro-platform-harmony-hybrid[\\/]dist[\\/]api[\\/]apis[\\/]taro/ }, ({ path }) => {
676
- const content = helper.fs.readFileSync(path).toString();
677
- return {
678
- contents: require('./api-loader')(content)
679
- };
680
- });
681
- },
646
+ }
682
647
  };
683
648
  prebundleOptions.esbuild || (prebundleOptions.esbuild = {});
684
649
  const esbuildConfig = prebundleOptions.esbuild;
@@ -706,17 +671,11 @@ var index = (ctx) => {
706
671
  };
707
672
  function setAlias(framework, chain) {
708
673
  const alias = chain.resolve.alias;
709
- switch (framework) {
710
- case 'preact':
711
- alias.set('react', 'preact/compat');
712
- alias.set('react-dom/test-utils', 'preact/test-utils');
713
- alias.set('react-dom', 'preact/compat');
714
- alias.set('react/jsx-runtime', 'preact/jsx-runtime');
715
- break;
716
- case 'nerv':
717
- alias.set('react$', 'nervjs');
718
- alias.set('react-dom$', 'nervjs');
719
- break;
674
+ if (framework === 'preact') {
675
+ alias.set('react', 'preact/compat');
676
+ alias.set('react-dom/test-utils', 'preact/test-utils');
677
+ alias.set('react-dom', 'preact/compat');
678
+ alias.set('react/jsx-runtime', 'preact/jsx-runtime');
720
679
  }
721
680
  }
722
681
  function VitePresetPlugin(framework) {
@@ -751,16 +710,6 @@ function viteCommonPlugin(framework) {
751
710
  ]
752
711
  : [];
753
712
  return {
754
- optimizeDeps: {
755
- esbuildOptions: {
756
- define: {
757
- __TARO_FRAMEWORK__: `"${framework}"`
758
- }
759
- }
760
- },
761
- define: {
762
- __TARO_FRAMEWORK__: `"${framework}"`,
763
- },
764
713
  resolve: {
765
714
  alias,
766
715
  },