@tarojs/plugin-framework-react 4.0.0-canary.8 → 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 +17 -3
- package/dist/api-loader.js.map +1 -1
- package/dist/index.js +94 -117
- package/dist/index.js.map +1 -1
- package/dist/runtime.js +114 -49
- package/dist/runtime.js.map +1 -1
- package/package.json +37 -33
package/LICENSE
CHANGED
|
@@ -154,7 +154,21 @@ See `/LICENSE` for details of the license.
|
|
|
154
154
|
|
|
155
155
|
==================
|
|
156
156
|
|
|
157
|
-
MIT (
|
|
158
|
-
The following files embed [
|
|
159
|
-
`/packages/taro-components
|
|
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.
|
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,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
|
-
|
|
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, 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 (
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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,17 +420,30 @@ function modifyH5WebpackChain(ctx, framework, chain) {
|
|
|
460
420
|
const externals = {};
|
|
461
421
|
if (isBuildNativeComp) {
|
|
462
422
|
// Note: 该模式不支持 prebundle 优化,不必再处理
|
|
463
|
-
externals.react =
|
|
464
|
-
|
|
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,
|
|
471
444
|
module: {
|
|
472
445
|
rule: {
|
|
473
|
-
'process-import-taro': {
|
|
446
|
+
'process-import-taro-h5': {
|
|
474
447
|
test: helper.REG_TARO_H5,
|
|
475
448
|
loader: require.resolve('./api-loader'),
|
|
476
449
|
},
|
|
@@ -503,6 +476,17 @@ function setPlugin(ctx, framework, chain) {
|
|
|
503
476
|
chain.plugin('fastRefreshPlugin').use(require('@prefresh/webpack'));
|
|
504
477
|
}
|
|
505
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
|
+
}
|
|
506
490
|
}
|
|
507
491
|
|
|
508
492
|
function modifyHarmonyWebpackChain(ctx, framework, chain) {
|
|
@@ -513,6 +497,11 @@ function setAlias$2(ctx, framework, chain) {
|
|
|
513
497
|
var _a;
|
|
514
498
|
const config = ctx.initialConfig;
|
|
515
499
|
const alias = chain.resolve.alias;
|
|
500
|
+
const mainFields = ['unpkg', ...helper.defaultMainFields];
|
|
501
|
+
const resolveOptions = {
|
|
502
|
+
basedir: process.cwd(),
|
|
503
|
+
mainFields,
|
|
504
|
+
};
|
|
516
505
|
if (framework === 'react') {
|
|
517
506
|
alias.set('react-dom$', '@tarojs/react');
|
|
518
507
|
alias.set('react-dom/client$', '@tarojs/react');
|
|
@@ -521,14 +510,14 @@ function setAlias$2(ctx, framework, chain) {
|
|
|
521
510
|
if (!isProd && ((_a = config.harmony) === null || _a === void 0 ? void 0 : _a.debugReact) !== true) {
|
|
522
511
|
// 不是生产环境,且没有设置 debugReact,则使用压缩版本的 react 依赖,减少体积
|
|
523
512
|
// 兼容pnpm workspace
|
|
524
|
-
const reactModulePath =
|
|
513
|
+
const reactModulePath = helper.resolveSync('react', resolveOptions);
|
|
525
514
|
const newFilePath = path.join(path.dirname(reactModulePath), 'cjs', 'react.production.min.js');
|
|
526
515
|
alias.set('react-reconciler$', 'react-reconciler/cjs/react-reconciler.production.min.js');
|
|
527
516
|
alias.set('react$', newFilePath);
|
|
528
517
|
alias.set('react/jsx-runtime$', 'react/cjs/react-jsx-runtime.production.min.js');
|
|
529
518
|
// 在React18中,使用了exports字段约定了模块暴露路径,其中并未暴露 ./cjs/ 。这将使上面的alias在编译时报错。相当的tricky。
|
|
530
519
|
// Why writeJson? prebundle will load package.json via readFile to check exports property.
|
|
531
|
-
const reactPkgPath =
|
|
520
|
+
const reactPkgPath = helper.resolveSync('react/package.json', resolveOptions);
|
|
532
521
|
if (reactPkgPath) {
|
|
533
522
|
const reactPkg = require('react/package.json');
|
|
534
523
|
const reactVersion = reactPkg.version || '';
|
|
@@ -544,7 +533,9 @@ function setAlias$2(ctx, framework, chain) {
|
|
|
544
533
|
}
|
|
545
534
|
function setLoader$1(framework, chain) {
|
|
546
535
|
chain.plugin('mainPlugin').tap((args) => {
|
|
547
|
-
|
|
536
|
+
var _a;
|
|
537
|
+
(_a = args[0]).loaderMeta || (_a.loaderMeta = {});
|
|
538
|
+
Object.assign(args[0].loaderMeta, getLoaderMeta(framework));
|
|
548
539
|
return args;
|
|
549
540
|
});
|
|
550
541
|
}
|
|
@@ -557,6 +548,11 @@ function setAlias$1(ctx, framework, chain) {
|
|
|
557
548
|
var _a;
|
|
558
549
|
const config = ctx.initialConfig;
|
|
559
550
|
const alias = chain.resolve.alias;
|
|
551
|
+
const mainFields = ['unpkg', ...helper.defaultMainFields];
|
|
552
|
+
const resolveOptions = {
|
|
553
|
+
basedir: process.cwd(),
|
|
554
|
+
mainFields,
|
|
555
|
+
};
|
|
560
556
|
if (framework === 'react') {
|
|
561
557
|
alias.set('react-dom$', '@tarojs/react');
|
|
562
558
|
alias.set('react-dom/client$', '@tarojs/react');
|
|
@@ -565,14 +561,14 @@ function setAlias$1(ctx, framework, chain) {
|
|
|
565
561
|
if (!isProd && ((_a = config.mini) === null || _a === void 0 ? void 0 : _a.debugReact) !== true) {
|
|
566
562
|
// 不是生产环境,且没有设置 debugReact,则使用压缩版本的 react 依赖,减少体积
|
|
567
563
|
// 兼容pnpm workspace
|
|
568
|
-
const reactModulePath =
|
|
564
|
+
const reactModulePath = helper.resolveSync('react', resolveOptions);
|
|
569
565
|
const newFilePath = path.join(path.dirname(reactModulePath), 'cjs', 'react.production.min.js');
|
|
570
566
|
alias.set('react-reconciler$', 'react-reconciler/cjs/react-reconciler.production.min.js');
|
|
571
567
|
alias.set(/^(?!.*mobx-react$).*react$/, newFilePath);
|
|
572
568
|
alias.set('react/jsx-runtime$', 'react/cjs/react-jsx-runtime.production.min.js');
|
|
573
569
|
// 在React18中,使用了exports字段约定了模块暴露路径,其中并未暴露 ./cjs/ 。这将使上面的alias在编译时报错。相当的tricky。
|
|
574
570
|
// Why writeJson? prebundle will load package.json via readFile to check exports property.
|
|
575
|
-
const reactPkgPath =
|
|
571
|
+
const reactPkgPath = helper.resolveSync('react/package.json', resolveOptions);
|
|
576
572
|
if (reactPkgPath) {
|
|
577
573
|
const reactPkg = require('react/package.json');
|
|
578
574
|
const reactVersion = reactPkg.version || '';
|
|
@@ -588,13 +584,15 @@ function setAlias$1(ctx, framework, chain) {
|
|
|
588
584
|
}
|
|
589
585
|
function setLoader(framework, chain) {
|
|
590
586
|
chain.plugin('miniPlugin').tap((args) => {
|
|
591
|
-
|
|
587
|
+
var _a;
|
|
588
|
+
(_a = args[0]).loaderMeta || (_a.loaderMeta = {});
|
|
589
|
+
Object.assign(args[0].loaderMeta, getLoaderMeta(framework));
|
|
592
590
|
return args;
|
|
593
591
|
});
|
|
594
592
|
}
|
|
595
593
|
|
|
596
594
|
function isReactLike(framework = 'react') {
|
|
597
|
-
return ['react', 'preact'
|
|
595
|
+
return ['react', 'preact'].includes(framework);
|
|
598
596
|
}
|
|
599
597
|
var index = (ctx) => {
|
|
600
598
|
const { framework = 'react' } = ctx.initialConfig;
|
|
@@ -603,12 +601,7 @@ var index = (ctx) => {
|
|
|
603
601
|
ctx.modifyWebpackChain(({ chain }) => {
|
|
604
602
|
// 通用
|
|
605
603
|
setAlias(framework, chain);
|
|
606
|
-
|
|
607
|
-
const config = args[0];
|
|
608
|
-
config.__TARO_FRAMEWORK__ = `"${framework}"`;
|
|
609
|
-
return args;
|
|
610
|
-
});
|
|
611
|
-
if (shared.isWebPlatform()) {
|
|
604
|
+
if (process.env.TARO_PLATFORM === 'web') {
|
|
612
605
|
// H5
|
|
613
606
|
modifyH5WebpackChain(ctx, framework, chain);
|
|
614
607
|
}
|
|
@@ -650,7 +643,7 @@ var index = (ctx) => {
|
|
|
650
643
|
contents: require('./api-loader')(content),
|
|
651
644
|
};
|
|
652
645
|
});
|
|
653
|
-
}
|
|
646
|
+
}
|
|
654
647
|
};
|
|
655
648
|
prebundleOptions.esbuild || (prebundleOptions.esbuild = {});
|
|
656
649
|
const esbuildConfig = prebundleOptions.esbuild;
|
|
@@ -661,7 +654,7 @@ var index = (ctx) => {
|
|
|
661
654
|
compiler.vitePlugins || (compiler.vitePlugins = []);
|
|
662
655
|
compiler.vitePlugins.push(viteCommonPlugin(framework));
|
|
663
656
|
compiler.vitePlugins.push(VitePresetPlugin(framework));
|
|
664
|
-
if (
|
|
657
|
+
if (process.env.TARO_PLATFORM === 'web') {
|
|
665
658
|
// H5
|
|
666
659
|
compiler.vitePlugins.push(h5iVitePlugin(ctx, framework));
|
|
667
660
|
}
|
|
@@ -678,17 +671,11 @@ var index = (ctx) => {
|
|
|
678
671
|
};
|
|
679
672
|
function setAlias(framework, chain) {
|
|
680
673
|
const alias = chain.resolve.alias;
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
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;
|
|
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');
|
|
692
679
|
}
|
|
693
680
|
}
|
|
694
681
|
function VitePresetPlugin(framework) {
|
|
@@ -723,16 +710,6 @@ function viteCommonPlugin(framework) {
|
|
|
723
710
|
]
|
|
724
711
|
: [];
|
|
725
712
|
return {
|
|
726
|
-
optimizeDeps: {
|
|
727
|
-
esbuildOptions: {
|
|
728
|
-
define: {
|
|
729
|
-
__TARO_FRAMEWORK__: `"${framework}"`
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
},
|
|
733
|
-
define: {
|
|
734
|
-
__TARO_FRAMEWORK__: `"${framework}"`,
|
|
735
|
-
},
|
|
736
713
|
resolve: {
|
|
737
714
|
alias,
|
|
738
715
|
},
|