@tarojs/plugin-framework-react 4.0.0-beta.13 → 4.0.0-beta.130

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);
@@ -285,7 +237,7 @@ function setTaroApi() {
285
237
  {
286
238
  name: 'taro:react-api',
287
239
  setup(build) {
288
- 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* () {
289
241
  const input = yield helper.fs.readFile(args.path, 'utf8');
290
242
  return {
291
243
  contents: apiLoader(input + '\n' + 'const taro = Taro__default\n')
@@ -298,7 +250,7 @@ function setTaroApi() {
298
250
  },
299
251
  }),
300
252
  load(id) {
301
- return __awaiter(this, void 0, void 0, function* () {
253
+ return tslib.__awaiter(this, void 0, void 0, function* () {
302
254
  if (process.env.NODE_ENV === 'production' && helper.REG_TARO_H5_RUNTIME_API.test(id)) {
303
255
  try {
304
256
  const input = yield helper.fs.readFile(id, 'utf8');
@@ -341,7 +293,8 @@ function injectLoaderMeta$1(ctx, framework) {
341
293
  const { getViteHarmonyCompilerContext } = runnerUtils;
342
294
  const viteCompilerContext = getViteHarmonyCompilerContext(this);
343
295
  if (viteCompilerContext) {
344
- viteCompilerContext.loaderMeta = getLoaderMeta(framework);
296
+ viteCompilerContext.loaderMeta || (viteCompilerContext.loaderMeta = {});
297
+ Object.assign(viteCompilerContext.loaderMeta, getLoaderMeta(framework));
345
298
  }
346
299
  }
347
300
  };
@@ -353,20 +306,21 @@ function aliasPlugin$1(ctx, framework) {
353
306
  config(config) {
354
307
  var _a;
355
308
  const alias = [
356
- { find: /react-dom$/, replacement: '@tarojs/react' }
309
+ { find: /react-dom$/, replacement: '@tarojs/react' },
310
+ { find: /react-dom\/client$/, replacement: '@tarojs/react' },
357
311
  ];
312
+ const mainFields = ['unpkg', ...helper.defaultMainFields];
313
+ const resolveOptions = {
314
+ basedir: process.cwd(),
315
+ mainFields,
316
+ };
358
317
  const isProd = config.mode === 'production';
359
318
  // TODO:harmony 目前会导致部分包用 production 版本,部分用 development 版本,导致许多 api 报错
360
319
  const isHarmony = ctx.runOpts.options.platform === 'harmony';
361
320
  if (!isProd && ((_a = ctx.initialConfig.harmony) === null || _a === void 0 ? void 0 : _a.debugReact) !== true && !isHarmony) {
362
- // 不是生产环境,且没有设置 debugReact,则使用压缩版本的 react 依赖,减少体积
363
- alias.push({ find: /react-reconciler$/, replacement: 'react-reconciler/cjs/react-reconciler.production.min.js' });
364
- alias.push({ find: /react$/, replacement: 'react/cjs/react.production.min.js' });
365
- alias.push({ find: /scheduler$/, replacement: 'scheduler/cjs/scheduler.production.min.js' });
366
- alias.push({ find: /react\/jsx-runtime$/, replacement: 'react/cjs/react-jsx-runtime.production.min.js' });
367
321
  // 在React18中,使用了exports字段约定了模块暴露路径,其中并未暴露 ./cjs/ 。这将使上面的alias在编译时报错。相当的tricky。
368
322
  // Why writeJson? prebundle will load package.json via readFile to check exports property.
369
- const reactPkgPath = require.resolve('react/package.json', { paths: [process.cwd()] });
323
+ const reactPkgPath = helper.resolveSync('react/package.json', resolveOptions);
370
324
  if (reactPkgPath) {
371
325
  const reactPkg = require('react/package.json');
372
326
  const reactVersion = (reactPkg.version || '');
@@ -403,7 +357,8 @@ function injectLoaderMeta(ctx, framework) {
403
357
  const { getViteMiniCompilerContext } = runnerUtils;
404
358
  const viteCompilerContext = getViteMiniCompilerContext(this);
405
359
  if (viteCompilerContext) {
406
- viteCompilerContext.loaderMeta = getLoaderMeta(framework);
360
+ viteCompilerContext.loaderMeta || (viteCompilerContext.loaderMeta = {});
361
+ Object.assign(viteCompilerContext.loaderMeta, getLoaderMeta(framework));
407
362
  }
408
363
  }
409
364
  };
@@ -415,8 +370,14 @@ function aliasPlugin(ctx, framework) {
415
370
  config(config) {
416
371
  var _a;
417
372
  const alias = [
418
- { find: /react-dom$/, replacement: '@tarojs/react' }
373
+ { find: /react-dom$/, replacement: '@tarojs/react' },
374
+ { find: /react-dom\/client$/, replacement: '@tarojs/react' },
419
375
  ];
376
+ const mainFields = ['unpkg', ...helper.defaultMainFields];
377
+ const resolveOptions = {
378
+ basedir: process.cwd(),
379
+ mainFields,
380
+ };
420
381
  const isProd = config.mode === 'production';
421
382
  // TODO:harmony 目前会导致部分包用 production 版本,部分用 development 版本,导致许多 api 报错
422
383
  const isHarmony = ctx.runOpts.options.platform === 'harmony';
@@ -428,7 +389,7 @@ function aliasPlugin(ctx, framework) {
428
389
  alias.push({ find: /react\/jsx-runtime$/, replacement: 'react/cjs/react-jsx-runtime.production.min.js' });
429
390
  // 在React18中,使用了exports字段约定了模块暴露路径,其中并未暴露 ./cjs/ 。这将使上面的alias在编译时报错。相当的tricky。
430
391
  // Why writeJson? prebundle will load package.json via readFile to check exports property.
431
- const reactPkgPath = require.resolve('react/package.json', { paths: [process.cwd()] });
392
+ const reactPkgPath = helper.resolveSync('react/package.json', resolveOptions);
432
393
  if (reactPkgPath) {
433
394
  const reactPkg = require('react/package.json');
434
395
  const reactVersion = (reactPkg.version || '');
@@ -489,28 +450,6 @@ function modifyH5WebpackChain(ctx, framework, chain) {
489
450
  },
490
451
  },
491
452
  });
492
- chain.merge({
493
- externals,
494
- module: {
495
- rule: {
496
- 'process-import-taro-harmony-hybrid': {
497
- test: /taro-platform-harmony-hybrid[\\/]dist[\\/]api[\\/]apis[\\/]taro/,
498
- loader: require.resolve('./api-loader')
499
- }
500
- }
501
- },
502
- });
503
- chain.merge({
504
- externals,
505
- module: {
506
- rule: {
507
- 'process-import-taro-harmony-hybrid': {
508
- test: /taro-platform-harmony-hybrid[\\/]dist[\\/]api[\\/]apis[\\/]taro/,
509
- loader: require.resolve('./api-loader')
510
- }
511
- }
512
- },
513
- });
514
453
  }
515
454
  function setLoader$2(framework, chain) {
516
455
  function customizer(object = '', sources = '') {
@@ -537,6 +476,17 @@ function setPlugin(ctx, framework, chain) {
537
476
  chain.plugin('fastRefreshPlugin').use(require('@prefresh/webpack'));
538
477
  }
539
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
+ }
540
490
  }
541
491
 
542
492
  function modifyHarmonyWebpackChain(ctx, framework, chain) {
@@ -547,6 +497,11 @@ function setAlias$2(ctx, framework, chain) {
547
497
  var _a;
548
498
  const config = ctx.initialConfig;
549
499
  const alias = chain.resolve.alias;
500
+ const mainFields = ['unpkg', ...helper.defaultMainFields];
501
+ const resolveOptions = {
502
+ basedir: process.cwd(),
503
+ mainFields,
504
+ };
550
505
  if (framework === 'react') {
551
506
  alias.set('react-dom$', '@tarojs/react');
552
507
  alias.set('react-dom/client$', '@tarojs/react');
@@ -555,14 +510,14 @@ function setAlias$2(ctx, framework, chain) {
555
510
  if (!isProd && ((_a = config.harmony) === null || _a === void 0 ? void 0 : _a.debugReact) !== true) {
556
511
  // 不是生产环境,且没有设置 debugReact,则使用压缩版本的 react 依赖,减少体积
557
512
  // 兼容pnpm workspace
558
- const reactModulePath = require.resolve('react', { paths: [process.cwd()] });
513
+ const reactModulePath = helper.resolveSync('react', resolveOptions);
559
514
  const newFilePath = path.join(path.dirname(reactModulePath), 'cjs', 'react.production.min.js');
560
515
  alias.set('react-reconciler$', 'react-reconciler/cjs/react-reconciler.production.min.js');
561
516
  alias.set('react$', newFilePath);
562
517
  alias.set('react/jsx-runtime$', 'react/cjs/react-jsx-runtime.production.min.js');
563
518
  // 在React18中,使用了exports字段约定了模块暴露路径,其中并未暴露 ./cjs/ 。这将使上面的alias在编译时报错。相当的tricky。
564
519
  // Why writeJson? prebundle will load package.json via readFile to check exports property.
565
- const reactPkgPath = require.resolve('react/package.json', { paths: [process.cwd()] });
520
+ const reactPkgPath = helper.resolveSync('react/package.json', resolveOptions);
566
521
  if (reactPkgPath) {
567
522
  const reactPkg = require('react/package.json');
568
523
  const reactVersion = reactPkg.version || '';
@@ -578,7 +533,9 @@ function setAlias$2(ctx, framework, chain) {
578
533
  }
579
534
  function setLoader$1(framework, chain) {
580
535
  chain.plugin('mainPlugin').tap((args) => {
581
- args[0].loaderMeta = getLoaderMeta(framework);
536
+ var _a;
537
+ (_a = args[0]).loaderMeta || (_a.loaderMeta = {});
538
+ Object.assign(args[0].loaderMeta, getLoaderMeta(framework));
582
539
  return args;
583
540
  });
584
541
  }
@@ -591,6 +548,11 @@ function setAlias$1(ctx, framework, chain) {
591
548
  var _a;
592
549
  const config = ctx.initialConfig;
593
550
  const alias = chain.resolve.alias;
551
+ const mainFields = ['unpkg', ...helper.defaultMainFields];
552
+ const resolveOptions = {
553
+ basedir: process.cwd(),
554
+ mainFields,
555
+ };
594
556
  if (framework === 'react') {
595
557
  alias.set('react-dom$', '@tarojs/react');
596
558
  alias.set('react-dom/client$', '@tarojs/react');
@@ -599,14 +561,14 @@ function setAlias$1(ctx, framework, chain) {
599
561
  if (!isProd && ((_a = config.mini) === null || _a === void 0 ? void 0 : _a.debugReact) !== true) {
600
562
  // 不是生产环境,且没有设置 debugReact,则使用压缩版本的 react 依赖,减少体积
601
563
  // 兼容pnpm workspace
602
- const reactModulePath = require.resolve('react', { paths: [process.cwd()] });
564
+ const reactModulePath = helper.resolveSync('react', resolveOptions);
603
565
  const newFilePath = path.join(path.dirname(reactModulePath), 'cjs', 'react.production.min.js');
604
566
  alias.set('react-reconciler$', 'react-reconciler/cjs/react-reconciler.production.min.js');
605
567
  alias.set(/^(?!.*mobx-react$).*react$/, newFilePath);
606
568
  alias.set('react/jsx-runtime$', 'react/cjs/react-jsx-runtime.production.min.js');
607
569
  // 在React18中,使用了exports字段约定了模块暴露路径,其中并未暴露 ./cjs/ 。这将使上面的alias在编译时报错。相当的tricky。
608
570
  // Why writeJson? prebundle will load package.json via readFile to check exports property.
609
- const reactPkgPath = require.resolve('react/package.json', { paths: [process.cwd()] });
571
+ const reactPkgPath = helper.resolveSync('react/package.json', resolveOptions);
610
572
  if (reactPkgPath) {
611
573
  const reactPkg = require('react/package.json');
612
574
  const reactVersion = reactPkg.version || '';
@@ -622,13 +584,15 @@ function setAlias$1(ctx, framework, chain) {
622
584
  }
623
585
  function setLoader(framework, chain) {
624
586
  chain.plugin('miniPlugin').tap((args) => {
625
- args[0].loaderMeta = getLoaderMeta(framework);
587
+ var _a;
588
+ (_a = args[0]).loaderMeta || (_a.loaderMeta = {});
589
+ Object.assign(args[0].loaderMeta, getLoaderMeta(framework));
626
590
  return args;
627
591
  });
628
592
  }
629
593
 
630
594
  function isReactLike(framework = 'react') {
631
- return ['react', 'preact', 'nerv', 'solid'].includes(framework);
595
+ return ['react', 'preact'].includes(framework);
632
596
  }
633
597
  var index = (ctx) => {
634
598
  const { framework = 'react' } = ctx.initialConfig;
@@ -637,11 +601,6 @@ var index = (ctx) => {
637
601
  ctx.modifyWebpackChain(({ chain }) => {
638
602
  // 通用
639
603
  setAlias(framework, chain);
640
- chain.plugin('definePlugin').tap((args) => {
641
- const config = args[0];
642
- config.__TARO_FRAMEWORK__ = `"${framework}"`;
643
- return args;
644
- });
645
604
  if (process.env.TARO_PLATFORM === 'web') {
646
605
  // H5
647
606
  modifyH5WebpackChain(ctx, framework, chain);
@@ -684,13 +643,7 @@ var index = (ctx) => {
684
643
  contents: require('./api-loader')(content),
685
644
  };
686
645
  });
687
- build.onLoad({ filter: /taro-platform-harmony-hybrid[\\/]dist[\\/]api[\\/]apis[\\/]taro/ }, ({ path }) => {
688
- const content = helper.fs.readFileSync(path).toString();
689
- return {
690
- contents: require('./api-loader')(content)
691
- };
692
- });
693
- },
646
+ }
694
647
  };
695
648
  prebundleOptions.esbuild || (prebundleOptions.esbuild = {});
696
649
  const esbuildConfig = prebundleOptions.esbuild;
@@ -718,17 +671,11 @@ var index = (ctx) => {
718
671
  };
719
672
  function setAlias(framework, chain) {
720
673
  const alias = chain.resolve.alias;
721
- switch (framework) {
722
- case 'preact':
723
- alias.set('react', 'preact/compat');
724
- alias.set('react-dom/test-utils', 'preact/test-utils');
725
- alias.set('react-dom', 'preact/compat');
726
- alias.set('react/jsx-runtime', 'preact/jsx-runtime');
727
- break;
728
- case 'nerv':
729
- alias.set('react$', 'nervjs');
730
- alias.set('react-dom$', 'nervjs');
731
- 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');
732
679
  }
733
680
  }
734
681
  function VitePresetPlugin(framework) {
@@ -763,16 +710,6 @@ function viteCommonPlugin(framework) {
763
710
  ]
764
711
  : [];
765
712
  return {
766
- optimizeDeps: {
767
- esbuildOptions: {
768
- define: {
769
- __TARO_FRAMEWORK__: `"${framework}"`
770
- }
771
- }
772
- },
773
- define: {
774
- __TARO_FRAMEWORK__: `"${framework}"`,
775
- },
776
713
  resolve: {
777
714
  alias,
778
715
  },