@tarojs/plugin-framework-react 4.0.0-beta.1 → 4.0.0-beta.100

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,7 +154,21 @@ 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`
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.
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/*`
160
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,10 +184,7 @@ 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
- if (shared.isWebPlatform()) {
187
+ if (process.env.TARO_PLATFORM === 'web') {
236
188
  if (framework === 'react') {
237
189
  const react = require('react');
238
190
  const majorVersion = Number((react.version || '18').split('.')[0]);
@@ -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,20 @@ 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' },
358
310
  ];
311
+ const mainFields = ['unpkg', ...helper.defaultMainFields];
312
+ const resolveOptions = {
313
+ basedir: process.cwd(),
314
+ mainFields,
315
+ };
359
316
  const isProd = config.mode === 'production';
360
317
  // TODO:harmony 目前会导致部分包用 production 版本,部分用 development 版本,导致许多 api 报错
361
318
  const isHarmony = ctx.runOpts.options.platform === 'harmony';
362
319
  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
320
  // 在React18中,使用了exports字段约定了模块暴露路径,其中并未暴露 ./cjs/ 。这将使上面的alias在编译时报错。相当的tricky。
369
321
  // Why writeJson? prebundle will load package.json via readFile to check exports property.
370
- const reactPkgPath = require.resolve('react/package.json', { paths: [process.cwd()] });
322
+ const reactPkgPath = helper.resolveSync('react/package.json', resolveOptions);
371
323
  if (reactPkgPath) {
372
324
  const reactPkg = require('react/package.json');
373
325
  const reactVersion = (reactPkg.version || '');
@@ -404,7 +356,8 @@ function injectLoaderMeta(ctx, framework) {
404
356
  const { getViteMiniCompilerContext } = runnerUtils;
405
357
  const viteCompilerContext = getViteMiniCompilerContext(this);
406
358
  if (viteCompilerContext) {
407
- viteCompilerContext.loaderMeta = getLoaderMeta(framework);
359
+ viteCompilerContext.loaderMeta || (viteCompilerContext.loaderMeta = {});
360
+ Object.assign(viteCompilerContext.loaderMeta, getLoaderMeta(framework));
408
361
  }
409
362
  }
410
363
  };
@@ -418,6 +371,11 @@ function aliasPlugin(ctx, framework) {
418
371
  const alias = [
419
372
  { find: /react-dom$/, replacement: '@tarojs/react' }
420
373
  ];
374
+ const mainFields = ['unpkg', ...helper.defaultMainFields];
375
+ const resolveOptions = {
376
+ basedir: process.cwd(),
377
+ mainFields,
378
+ };
421
379
  const isProd = config.mode === 'production';
422
380
  // TODO:harmony 目前会导致部分包用 production 版本,部分用 development 版本,导致许多 api 报错
423
381
  const isHarmony = ctx.runOpts.options.platform === 'harmony';
@@ -429,7 +387,7 @@ function aliasPlugin(ctx, framework) {
429
387
  alias.push({ find: /react\/jsx-runtime$/, replacement: 'react/cjs/react-jsx-runtime.production.min.js' });
430
388
  // 在React18中,使用了exports字段约定了模块暴露路径,其中并未暴露 ./cjs/ 。这将使上面的alias在编译时报错。相当的tricky。
431
389
  // Why writeJson? prebundle will load package.json via readFile to check exports property.
432
- const reactPkgPath = require.resolve('react/package.json', { paths: [process.cwd()] });
390
+ const reactPkgPath = helper.resolveSync('react/package.json', resolveOptions);
433
391
  if (reactPkgPath) {
434
392
  const reactPkg = require('react/package.json');
435
393
  const reactVersion = (reactPkg.version || '');
@@ -460,17 +418,30 @@ function modifyH5WebpackChain(ctx, framework, chain) {
460
418
  const externals = {};
461
419
  if (isBuildNativeComp) {
462
420
  // Note: 该模式不支持 prebundle 优化,不必再处理
463
- externals.react = 'React';
464
- externals['react-dom'] = 'ReactDOM';
421
+ externals.react = {
422
+ commonjs: 'react',
423
+ commonjs2: 'react',
424
+ amd: 'react',
425
+ root: 'React'
426
+ };
427
+ externals['react-dom'] = {
428
+ commonjs: 'react-dom',
429
+ commonjs2: 'react-dom',
430
+ amd: 'react-dom',
431
+ root: 'ReactDOM'
432
+ };
465
433
  if (framework === 'preact') {
466
434
  externals.preact = 'preact';
467
435
  }
436
+ chain.merge({
437
+ externalsType: 'umd'
438
+ });
468
439
  }
469
440
  chain.merge({
470
441
  externals,
471
442
  module: {
472
443
  rule: {
473
- 'process-import-taro': {
444
+ 'process-import-taro-h5': {
474
445
  test: helper.REG_TARO_H5,
475
446
  loader: require.resolve('./api-loader'),
476
447
  },
@@ -503,6 +474,17 @@ function setPlugin(ctx, framework, chain) {
503
474
  chain.plugin('fastRefreshPlugin').use(require('@prefresh/webpack'));
504
475
  }
505
476
  }
477
+ const mainFields = ['unpkg', ...helper.defaultMainFields];
478
+ const resolveOptions = {
479
+ basedir: process.cwd(),
480
+ mainFields,
481
+ };
482
+ if (framework === 'react') {
483
+ const alias = chain.resolve.alias;
484
+ // Note: 本地 link 调试时,避免 react 重复打包
485
+ alias.set('react$', helper.resolveSync('react', resolveOptions));
486
+ alias.set('react-dom$', helper.resolveSync('react-dom', resolveOptions));
487
+ }
506
488
  }
507
489
 
508
490
  function modifyHarmonyWebpackChain(ctx, framework, chain) {
@@ -513,6 +495,11 @@ function setAlias$2(ctx, framework, chain) {
513
495
  var _a;
514
496
  const config = ctx.initialConfig;
515
497
  const alias = chain.resolve.alias;
498
+ const mainFields = ['unpkg', ...helper.defaultMainFields];
499
+ const resolveOptions = {
500
+ basedir: process.cwd(),
501
+ mainFields,
502
+ };
516
503
  if (framework === 'react') {
517
504
  alias.set('react-dom$', '@tarojs/react');
518
505
  alias.set('react-dom/client$', '@tarojs/react');
@@ -521,14 +508,14 @@ function setAlias$2(ctx, framework, chain) {
521
508
  if (!isProd && ((_a = config.harmony) === null || _a === void 0 ? void 0 : _a.debugReact) !== true) {
522
509
  // 不是生产环境,且没有设置 debugReact,则使用压缩版本的 react 依赖,减少体积
523
510
  // 兼容pnpm workspace
524
- const reactModulePath = require.resolve('react', { paths: [process.cwd()] });
511
+ const reactModulePath = helper.resolveSync('react', resolveOptions);
525
512
  const newFilePath = path.join(path.dirname(reactModulePath), 'cjs', 'react.production.min.js');
526
513
  alias.set('react-reconciler$', 'react-reconciler/cjs/react-reconciler.production.min.js');
527
514
  alias.set('react$', newFilePath);
528
515
  alias.set('react/jsx-runtime$', 'react/cjs/react-jsx-runtime.production.min.js');
529
516
  // 在React18中,使用了exports字段约定了模块暴露路径,其中并未暴露 ./cjs/ 。这将使上面的alias在编译时报错。相当的tricky。
530
517
  // Why writeJson? prebundle will load package.json via readFile to check exports property.
531
- const reactPkgPath = require.resolve('react/package.json', { paths: [process.cwd()] });
518
+ const reactPkgPath = helper.resolveSync('react/package.json', resolveOptions);
532
519
  if (reactPkgPath) {
533
520
  const reactPkg = require('react/package.json');
534
521
  const reactVersion = reactPkg.version || '';
@@ -544,7 +531,9 @@ function setAlias$2(ctx, framework, chain) {
544
531
  }
545
532
  function setLoader$1(framework, chain) {
546
533
  chain.plugin('mainPlugin').tap((args) => {
547
- args[0].loaderMeta = getLoaderMeta(framework);
534
+ var _a;
535
+ (_a = args[0]).loaderMeta || (_a.loaderMeta = {});
536
+ Object.assign(args[0].loaderMeta, getLoaderMeta(framework));
548
537
  return args;
549
538
  });
550
539
  }
@@ -557,6 +546,11 @@ function setAlias$1(ctx, framework, chain) {
557
546
  var _a;
558
547
  const config = ctx.initialConfig;
559
548
  const alias = chain.resolve.alias;
549
+ const mainFields = ['unpkg', ...helper.defaultMainFields];
550
+ const resolveOptions = {
551
+ basedir: process.cwd(),
552
+ mainFields,
553
+ };
560
554
  if (framework === 'react') {
561
555
  alias.set('react-dom$', '@tarojs/react');
562
556
  alias.set('react-dom/client$', '@tarojs/react');
@@ -565,14 +559,14 @@ function setAlias$1(ctx, framework, chain) {
565
559
  if (!isProd && ((_a = config.mini) === null || _a === void 0 ? void 0 : _a.debugReact) !== true) {
566
560
  // 不是生产环境,且没有设置 debugReact,则使用压缩版本的 react 依赖,减少体积
567
561
  // 兼容pnpm workspace
568
- const reactModulePath = require.resolve('react', { paths: [process.cwd()] });
562
+ const reactModulePath = helper.resolveSync('react', resolveOptions);
569
563
  const newFilePath = path.join(path.dirname(reactModulePath), 'cjs', 'react.production.min.js');
570
564
  alias.set('react-reconciler$', 'react-reconciler/cjs/react-reconciler.production.min.js');
571
565
  alias.set(/^(?!.*mobx-react$).*react$/, newFilePath);
572
566
  alias.set('react/jsx-runtime$', 'react/cjs/react-jsx-runtime.production.min.js');
573
567
  // 在React18中,使用了exports字段约定了模块暴露路径,其中并未暴露 ./cjs/ 。这将使上面的alias在编译时报错。相当的tricky。
574
568
  // Why writeJson? prebundle will load package.json via readFile to check exports property.
575
- const reactPkgPath = require.resolve('react/package.json', { paths: [process.cwd()] });
569
+ const reactPkgPath = helper.resolveSync('react/package.json', resolveOptions);
576
570
  if (reactPkgPath) {
577
571
  const reactPkg = require('react/package.json');
578
572
  const reactVersion = reactPkg.version || '';
@@ -588,13 +582,15 @@ function setAlias$1(ctx, framework, chain) {
588
582
  }
589
583
  function setLoader(framework, chain) {
590
584
  chain.plugin('miniPlugin').tap((args) => {
591
- args[0].loaderMeta = getLoaderMeta(framework);
585
+ var _a;
586
+ (_a = args[0]).loaderMeta || (_a.loaderMeta = {});
587
+ Object.assign(args[0].loaderMeta, getLoaderMeta(framework));
592
588
  return args;
593
589
  });
594
590
  }
595
591
 
596
592
  function isReactLike(framework = 'react') {
597
- return ['react', 'preact', 'nerv', 'solid'].includes(framework);
593
+ return ['react', 'preact'].includes(framework);
598
594
  }
599
595
  var index = (ctx) => {
600
596
  const { framework = 'react' } = ctx.initialConfig;
@@ -603,12 +599,7 @@ var index = (ctx) => {
603
599
  ctx.modifyWebpackChain(({ chain }) => {
604
600
  // 通用
605
601
  setAlias(framework, chain);
606
- chain.plugin('definePlugin').tap((args) => {
607
- const config = args[0];
608
- config.__TARO_FRAMEWORK__ = `"${framework}"`;
609
- return args;
610
- });
611
- if (shared.isWebPlatform()) {
602
+ if (process.env.TARO_PLATFORM === 'web') {
612
603
  // H5
613
604
  modifyH5WebpackChain(ctx, framework, chain);
614
605
  }
@@ -650,7 +641,7 @@ var index = (ctx) => {
650
641
  contents: require('./api-loader')(content),
651
642
  };
652
643
  });
653
- },
644
+ }
654
645
  };
655
646
  prebundleOptions.esbuild || (prebundleOptions.esbuild = {});
656
647
  const esbuildConfig = prebundleOptions.esbuild;
@@ -661,7 +652,7 @@ var index = (ctx) => {
661
652
  compiler.vitePlugins || (compiler.vitePlugins = []);
662
653
  compiler.vitePlugins.push(viteCommonPlugin(framework));
663
654
  compiler.vitePlugins.push(VitePresetPlugin(framework));
664
- if (shared.isWebPlatform()) {
655
+ if (process.env.TARO_PLATFORM === 'web') {
665
656
  // H5
666
657
  compiler.vitePlugins.push(h5iVitePlugin(ctx, framework));
667
658
  }
@@ -678,17 +669,11 @@ var index = (ctx) => {
678
669
  };
679
670
  function setAlias(framework, chain) {
680
671
  const alias = chain.resolve.alias;
681
- switch (framework) {
682
- case 'preact':
683
- alias.set('react', 'preact/compat');
684
- alias.set('react-dom/test-utils', 'preact/test-utils');
685
- alias.set('react-dom', 'preact/compat');
686
- alias.set('react/jsx-runtime', 'preact/jsx-runtime');
687
- break;
688
- case 'nerv':
689
- alias.set('react$', 'nervjs');
690
- alias.set('react-dom$', 'nervjs');
691
- break;
672
+ if (framework === 'preact') {
673
+ alias.set('react', 'preact/compat');
674
+ alias.set('react-dom/test-utils', 'preact/test-utils');
675
+ alias.set('react-dom', 'preact/compat');
676
+ alias.set('react/jsx-runtime', 'preact/jsx-runtime');
692
677
  }
693
678
  }
694
679
  function VitePresetPlugin(framework) {
@@ -723,16 +708,6 @@ function viteCommonPlugin(framework) {
723
708
  ]
724
709
  : [];
725
710
  return {
726
- optimizeDeps: {
727
- esbuildOptions: {
728
- define: {
729
- __TARO_FRAMEWORK__: `"${framework}"`
730
- }
731
- }
732
- },
733
- define: {
734
- __TARO_FRAMEWORK__: `"${framework}"`,
735
- },
736
711
  resolve: {
737
712
  alias,
738
713
  },