@tarojs/plugin-platform-h5 4.0.1 → 4.0.2

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/dist/index.js CHANGED
@@ -2,409 +2,15 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var service = require('@tarojs/service');
5
+ var tslib = require('tslib');
6
6
  var path = require('node:path');
7
- var resolve = require('resolve');
8
-
9
- function _interopNamespaceDefault(e) {
10
- var n = Object.create(null);
11
- if (e) {
12
- Object.keys(e).forEach(function (k) {
13
- if (k !== 'default') {
14
- var d = Object.getOwnPropertyDescriptor(e, k);
15
- Object.defineProperty(n, k, d.get ? d : {
16
- enumerable: true,
17
- get: function () { return e[k]; }
18
- });
19
- }
20
- });
21
- }
22
- n.default = e;
23
- return Object.freeze(n);
24
- }
25
-
26
- var resolve__namespace = /*#__PURE__*/_interopNamespaceDefault(resolve);
27
-
28
- /******************************************************************************
29
- Copyright (c) Microsoft Corporation.
30
-
31
- Permission to use, copy, modify, and/or distribute this software for any
32
- purpose with or without fee is hereby granted.
33
-
34
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
35
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
36
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
37
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
38
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
39
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
40
- PERFORMANCE OF THIS SOFTWARE.
41
- ***************************************************************************** */
42
- /* global Reflect, Promise, SuppressedError, Symbol */
43
-
44
- var extendStatics = function(d, b) {
45
- extendStatics = Object.setPrototypeOf ||
46
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
47
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
48
- return extendStatics(d, b);
49
- };
50
-
51
- function __extends(d, b) {
52
- if (typeof b !== "function" && b !== null)
53
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
54
- extendStatics(d, b);
55
- function __() { this.constructor = d; }
56
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
57
- }
58
-
59
- var __assign = function() {
60
- __assign = Object.assign || function __assign(t) {
61
- for (var s, i = 1, n = arguments.length; i < n; i++) {
62
- s = arguments[i];
63
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
64
- }
65
- return t;
66
- };
67
- return __assign.apply(this, arguments);
68
- };
69
-
70
- function __rest(s, e) {
71
- var t = {};
72
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
73
- t[p] = s[p];
74
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
75
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
76
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
77
- t[p[i]] = s[p[i]];
78
- }
79
- return t;
80
- }
81
-
82
- function __decorate(decorators, target, key, desc) {
83
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
84
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
85
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
86
- return c > 3 && r && Object.defineProperty(target, key, r), r;
87
- }
88
-
89
- function __param(paramIndex, decorator) {
90
- return function (target, key) { decorator(target, key, paramIndex); }
91
- }
92
-
93
- function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
94
- function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
95
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
96
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
97
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
98
- var _, done = false;
99
- for (var i = decorators.length - 1; i >= 0; i--) {
100
- var context = {};
101
- for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
102
- for (var p in contextIn.access) context.access[p] = contextIn.access[p];
103
- context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
104
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
105
- if (kind === "accessor") {
106
- if (result === void 0) continue;
107
- if (result === null || typeof result !== "object") throw new TypeError("Object expected");
108
- if (_ = accept(result.get)) descriptor.get = _;
109
- if (_ = accept(result.set)) descriptor.set = _;
110
- if (_ = accept(result.init)) initializers.unshift(_);
111
- }
112
- else if (_ = accept(result)) {
113
- if (kind === "field") initializers.unshift(_);
114
- else descriptor[key] = _;
115
- }
116
- }
117
- if (target) Object.defineProperty(target, contextIn.name, descriptor);
118
- done = true;
119
- };
120
-
121
- function __runInitializers(thisArg, initializers, value) {
122
- var useValue = arguments.length > 2;
123
- for (var i = 0; i < initializers.length; i++) {
124
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
125
- }
126
- return useValue ? value : void 0;
127
- };
128
-
129
- function __propKey(x) {
130
- return typeof x === "symbol" ? x : "".concat(x);
131
- };
132
-
133
- function __setFunctionName(f, name, prefix) {
134
- if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
135
- return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
136
- };
137
-
138
- function __metadata(metadataKey, metadataValue) {
139
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
140
- }
141
-
142
- function __awaiter(thisArg, _arguments, P, generator) {
143
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
144
- return new (P || (P = Promise))(function (resolve, reject) {
145
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
146
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
147
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
148
- step((generator = generator.apply(thisArg, _arguments || [])).next());
149
- });
150
- }
151
-
152
- function __generator(thisArg, body) {
153
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
154
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
155
- function verb(n) { return function (v) { return step([n, v]); }; }
156
- function step(op) {
157
- if (f) throw new TypeError("Generator is already executing.");
158
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
159
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
160
- if (y = 0, t) op = [op[0] & 2, t.value];
161
- switch (op[0]) {
162
- case 0: case 1: t = op; break;
163
- case 4: _.label++; return { value: op[1], done: false };
164
- case 5: _.label++; y = op[1]; op = [0]; continue;
165
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
166
- default:
167
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
168
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
169
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
170
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
171
- if (t[2]) _.ops.pop();
172
- _.trys.pop(); continue;
173
- }
174
- op = body.call(thisArg, _);
175
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
176
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
177
- }
178
- }
179
-
180
- var __createBinding = Object.create ? (function(o, m, k, k2) {
181
- if (k2 === undefined) k2 = k;
182
- var desc = Object.getOwnPropertyDescriptor(m, k);
183
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
184
- desc = { enumerable: true, get: function() { return m[k]; } };
185
- }
186
- Object.defineProperty(o, k2, desc);
187
- }) : (function(o, m, k, k2) {
188
- if (k2 === undefined) k2 = k;
189
- o[k2] = m[k];
190
- });
191
-
192
- function __exportStar(m, o) {
193
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);
194
- }
195
-
196
- function __values(o) {
197
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
198
- if (m) return m.call(o);
199
- if (o && typeof o.length === "number") return {
200
- next: function () {
201
- if (o && i >= o.length) o = void 0;
202
- return { value: o && o[i++], done: !o };
203
- }
204
- };
205
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
206
- }
207
-
208
- function __read(o, n) {
209
- var m = typeof Symbol === "function" && o[Symbol.iterator];
210
- if (!m) return o;
211
- var i = m.call(o), r, ar = [], e;
212
- try {
213
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
214
- }
215
- catch (error) { e = { error: error }; }
216
- finally {
217
- try {
218
- if (r && !r.done && (m = i["return"])) m.call(i);
219
- }
220
- finally { if (e) throw e.error; }
221
- }
222
- return ar;
223
- }
224
-
225
- /** @deprecated */
226
- function __spread() {
227
- for (var ar = [], i = 0; i < arguments.length; i++)
228
- ar = ar.concat(__read(arguments[i]));
229
- return ar;
230
- }
231
-
232
- /** @deprecated */
233
- function __spreadArrays() {
234
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
235
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
236
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
237
- r[k] = a[j];
238
- return r;
239
- }
240
-
241
- function __spreadArray(to, from, pack) {
242
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
243
- if (ar || !(i in from)) {
244
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
245
- ar[i] = from[i];
246
- }
247
- }
248
- return to.concat(ar || Array.prototype.slice.call(from));
249
- }
250
-
251
- function __await(v) {
252
- return this instanceof __await ? (this.v = v, this) : new __await(v);
253
- }
254
-
255
- function __asyncGenerator(thisArg, _arguments, generator) {
256
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
257
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
258
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
259
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
260
- function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
261
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
262
- function fulfill(value) { resume("next", value); }
263
- function reject(value) { resume("throw", value); }
264
- function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
265
- }
266
-
267
- function __asyncDelegator(o) {
268
- var i, p;
269
- return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
270
- function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }
271
- }
272
-
273
- function __asyncValues(o) {
274
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
275
- var m = o[Symbol.asyncIterator], i;
276
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
277
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
278
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
279
- }
280
-
281
- function __makeTemplateObject(cooked, raw) {
282
- if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
283
- return cooked;
284
- };
285
-
286
- var __setModuleDefault = Object.create ? (function(o, v) {
287
- Object.defineProperty(o, "default", { enumerable: true, value: v });
288
- }) : function(o, v) {
289
- o["default"] = v;
290
- };
291
-
292
- function __importStar(mod) {
293
- if (mod && mod.__esModule) return mod;
294
- var result = {};
295
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
296
- __setModuleDefault(result, mod);
297
- return result;
298
- }
299
-
300
- function __importDefault(mod) {
301
- return (mod && mod.__esModule) ? mod : { default: mod };
302
- }
303
-
304
- function __classPrivateFieldGet(receiver, state, kind, f) {
305
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
306
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
307
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
308
- }
309
-
310
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
311
- if (kind === "m") throw new TypeError("Private method is not writable");
312
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
313
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
314
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
315
- }
316
-
317
- function __classPrivateFieldIn(state, receiver) {
318
- if (receiver === null || (typeof receiver !== "object" && typeof receiver !== "function")) throw new TypeError("Cannot use 'in' operator on non-object");
319
- return typeof state === "function" ? receiver === state : state.has(receiver);
320
- }
321
-
322
- function __addDisposableResource(env, value, async) {
323
- if (value !== null && value !== void 0) {
324
- if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
325
- var dispose;
326
- if (async) {
327
- if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
328
- dispose = value[Symbol.asyncDispose];
329
- }
330
- if (dispose === void 0) {
331
- if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
332
- dispose = value[Symbol.dispose];
333
- }
334
- if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
335
- env.stack.push({ value: value, dispose: dispose, async: async });
336
- }
337
- else if (async) {
338
- env.stack.push({ async: true });
339
- }
340
- return value;
341
- }
342
-
343
- var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
344
- var e = new Error(message);
345
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
346
- };
347
-
348
- function __disposeResources(env) {
349
- function fail(e) {
350
- env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
351
- env.hasError = true;
352
- }
353
- function next() {
354
- while (env.stack.length) {
355
- var rec = env.stack.pop();
356
- try {
357
- var result = rec.dispose && rec.dispose.call(rec.value);
358
- if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
359
- }
360
- catch (e) {
361
- fail(e);
362
- }
363
- }
364
- if (env.hasError) throw env.error;
365
- }
366
- return next();
367
- }
368
-
369
- var tslib_es6 = {
370
- __extends: __extends,
371
- __assign: __assign,
372
- __rest: __rest,
373
- __decorate: __decorate,
374
- __param: __param,
375
- __metadata: __metadata,
376
- __awaiter: __awaiter,
377
- __generator: __generator,
378
- __createBinding: __createBinding,
379
- __exportStar: __exportStar,
380
- __values: __values,
381
- __read: __read,
382
- __spread: __spread,
383
- __spreadArrays: __spreadArrays,
384
- __spreadArray: __spreadArray,
385
- __await: __await,
386
- __asyncGenerator: __asyncGenerator,
387
- __asyncDelegator: __asyncDelegator,
388
- __asyncValues: __asyncValues,
389
- __makeTemplateObject: __makeTemplateObject,
390
- __importStar: __importStar,
391
- __importDefault: __importDefault,
392
- __classPrivateFieldGet: __classPrivateFieldGet,
393
- __classPrivateFieldSet: __classPrivateFieldSet,
394
- __classPrivateFieldIn: __classPrivateFieldIn,
395
- __addDisposableResource: __addDisposableResource,
396
- __disposeResources: __disposeResources,
397
- };
398
-
399
- function resolveSync(id, opts = {
400
- basedir: __dirname
401
- }) {
402
- return resolve__namespace.sync(id, opts);
403
- }
7
+ var core = require('@babel/core');
8
+ var helper = require('@tarojs/helper');
9
+ var service = require('@tarojs/service');
404
10
 
405
11
  const compLibraryAlias = {
406
- vue: 'vue2',
407
- vue3: 'vue3'
12
+ vue3: 'vue3',
13
+ solid: 'solid',
408
14
  };
409
15
  const PACKAGE_NAME = '@tarojs/plugin-platform-h5';
410
16
  class H5 extends service.TaroPlatformWeb {
@@ -412,10 +18,11 @@ class H5 extends service.TaroPlatformWeb {
412
18
  super(ctx, config);
413
19
  this.platform = 'h5';
414
20
  this.runtimePath = `${PACKAGE_NAME}/dist/runtime`;
21
+ this.mainFields = [...helper.defaultMainFields];
415
22
  this.setupTransaction.addWrapper({
416
23
  close() {
417
- this.modifyWebpackConfig();
418
- }
24
+ this.compiler === 'webpack5' ? this.modifyWebpackConfig() : this.modifyViteConfig();
25
+ },
419
26
  });
420
27
  }
421
28
  get framework() {
@@ -437,6 +44,9 @@ class H5 extends service.TaroPlatformWeb {
437
44
  }
438
45
  get componentLibrary() {
439
46
  if (this.useHtmlComponents && this.aliasFramework === 'react') {
47
+ if (this.framework === 'solid') {
48
+ return require.resolve('@tarojs/components-react/dist/solid');
49
+ }
440
50
  return require.resolve('./runtime/components');
441
51
  }
442
52
  else if (this.useDeprecatedAdapterComponent) {
@@ -450,24 +60,39 @@ class H5 extends service.TaroPlatformWeb {
450
60
  return path.join(path.dirname(require.resolve('@tarojs/components')), '..', 'lib');
451
61
  }
452
62
  get routerLibrary() {
453
- return require.resolve('@tarojs/router');
63
+ const name = '@tarojs/router';
64
+ return (helper.resolveSync(name, {
65
+ // basedir: this.ctx.paths.appPath,
66
+ mainFields: this.mainFields,
67
+ }) || name);
454
68
  }
455
69
  get libraryDefinition() {
456
- return resolveSync('./definition.json');
70
+ return helper.resolveSync('./definition.json', {
71
+ basedir: __dirname,
72
+ });
457
73
  }
458
74
  /**
459
75
  * 修改 Webpack 配置
460
76
  */
461
77
  modifyWebpackConfig() {
462
- this.ctx.modifyWebpackChain(({ chain }) => {
78
+ var _a, _b;
79
+ (_b = (_a = this.ctx).modifyWebpackChain) === null || _b === void 0 ? void 0 : _b.call(_a, ({ chain }) => {
80
+ // Note: 更新 mainFields 配置,确保 resolveSync 能正确读取到相关依赖入口文件
81
+ const mainFields = chain.resolve.mainFields.values() || [...helper.defaultMainFields];
82
+ if (mainFields.length > 0) {
83
+ this.mainFields = mainFields;
84
+ }
463
85
  const rules = chain.module.rules;
464
86
  const script = rules.get('script');
465
87
  const babelLoader = script.uses.get('babelLoader');
466
88
  babelLoader.set('options', Object.assign(Object.assign({}, babelLoader.get('options')), { plugins: [
467
- [require('babel-plugin-transform-taroapi'), {
89
+ [
90
+ require('babel-plugin-transform-taroapi'),
91
+ {
468
92
  packageName: '@tarojs/taro',
469
- definition: require(this.libraryDefinition)
470
- }]
93
+ definition: require(this.libraryDefinition),
94
+ },
95
+ ],
471
96
  ] }));
472
97
  const alias = chain.resolve.alias;
473
98
  // TODO 考虑集成到 taroComponentsPath 中,与小程序端对齐
@@ -475,12 +100,11 @@ class H5 extends service.TaroPlatformWeb {
475
100
  alias.set('@tarojs/components/lib', this.componentAdapter);
476
101
  alias.set('@tarojs/router$', this.routerLibrary);
477
102
  alias.set('@tarojs/taro', this.apiLibrary);
478
- chain.plugin('mainPlugin')
479
- .tap(args => {
103
+ chain.plugin('mainPlugin').tap((args) => {
480
104
  var _a;
481
105
  (_a = args[0]).loaderMeta || (_a.loaderMeta = {
482
106
  extraImportForWeb: '',
483
- execBeforeCreateWebApp: ''
107
+ execBeforeCreateWebApp: '',
484
108
  });
485
109
  // Note: 旧版本适配器不会自动注册 Web Components 组件,需要加载 defineCustomElements 脚本自动注册使用的组件
486
110
  if (this.useDeprecatedAdapterComponent) {
@@ -492,10 +116,6 @@ class H5 extends service.TaroPlatformWeb {
492
116
  args[0].loaderMeta.execBeforeCreateWebApp += `defineCustomElementTaroPullToRefreshCore()\n`;
493
117
  }
494
118
  switch (this.framework) {
495
- case 'vue':
496
- args[0].loaderMeta.extraImportForWeb += `import { initVue2Components } from '@tarojs/components/lib/vue2/components-loader'\nimport * as list from '@tarojs/components'\n`;
497
- args[0].loaderMeta.execBeforeCreateWebApp += `initVue2Components(list)\n`;
498
- break;
499
119
  case 'vue3':
500
120
  args[0].loaderMeta.extraImportForWeb += `import { initVue3Components } from '@tarojs/components/lib/vue3/components-loader'\nimport * as list from '@tarojs/components'\n`;
501
121
  args[0].loaderMeta.execBeforeCreateWebApp += `initVue3Components(component, list)\n`;
@@ -509,8 +129,108 @@ class H5 extends service.TaroPlatformWeb {
509
129
  return args;
510
130
  });
511
131
  // Note: 本地调试 stencil 组件库时,如果启用 sourceMap 则需要相关配置
512
- chain.module.rule('map')
513
- .test(/\.map$/).type('json');
132
+ chain.module
133
+ .rule('map')
134
+ .test(/\.map$/)
135
+ .type('json');
136
+ });
137
+ }
138
+ /**
139
+ * 修改 Vite 配置
140
+ */
141
+ modifyViteConfig() {
142
+ var _a, _b;
143
+ const that = this;
144
+ const { runnerUtils } = this.ctx;
145
+ const { getViteH5CompilerContext } = runnerUtils;
146
+ (_b = (_a = that.ctx).modifyViteConfig) === null || _b === void 0 ? void 0 : _b.call(_a, ({ viteConfig }) => {
147
+ function aliasPlugin() {
148
+ return {
149
+ name: 'taro:vite-h5-alias',
150
+ config: () => ({
151
+ resolve: {
152
+ alias: [
153
+ { find: /@tarojs\/components$/, replacement: that.componentLibrary },
154
+ { find: '@tarojs/components/lib', replacement: that.componentAdapter },
155
+ { find: /@tarojs\/router$/, replacement: that.routerLibrary },
156
+ { find: '@tarojs/taro', replacement: that.apiLibrary },
157
+ ],
158
+ },
159
+ }),
160
+ };
161
+ }
162
+ function injectLoaderMeta() {
163
+ return {
164
+ name: 'taro:vite-h5-loader-meta',
165
+ buildStart() {
166
+ return tslib.__awaiter(this, void 0, void 0, function* () {
167
+ const viteCompilerContext = yield getViteH5CompilerContext(this);
168
+ if (viteCompilerContext) {
169
+ viteCompilerContext.loaderMeta || (viteCompilerContext.loaderMeta = {
170
+ extraImportForWeb: '',
171
+ execBeforeCreateWebApp: '',
172
+ });
173
+ // Note: 旧版本适配器不会自动注册 Web Components 组件,需要加载 defineCustomElements 脚本自动注册使用的组件
174
+ if (that.useDeprecatedAdapterComponent) {
175
+ viteCompilerContext.loaderMeta.extraImportForWeb += `import { applyPolyfills, defineCustomElements } from '@tarojs/components/loader'\n`;
176
+ viteCompilerContext.loaderMeta.execBeforeCreateWebApp += `applyPolyfills().then(() => defineCustomElements(window))\n`;
177
+ }
178
+ if (!that.useHtmlComponents) {
179
+ viteCompilerContext.loaderMeta.extraImportForWeb += `import { defineCustomElementTaroPullToRefreshCore } from '@tarojs/components/dist/components'\n`;
180
+ viteCompilerContext.loaderMeta.execBeforeCreateWebApp += `defineCustomElementTaroPullToRefreshCore()\n`;
181
+ }
182
+ switch (that.framework) {
183
+ case 'vue3':
184
+ viteCompilerContext.loaderMeta.extraImportForWeb += `import { initVue3Components } from '@tarojs/components/lib/vue3/components-loader'\nimport * as list from '@tarojs/components'\n`;
185
+ viteCompilerContext.loaderMeta.execBeforeCreateWebApp += `initVue3Components(component, list)\n`;
186
+ break;
187
+ default:
188
+ if (that.useHtmlComponents) {
189
+ viteCompilerContext.loaderMeta.extraImportForWeb += `import { PullDownRefresh } from '@tarojs/components'\n`;
190
+ viteCompilerContext.loaderMeta.execBeforeCreateWebApp += `config.PullDownRefresh = PullDownRefresh\n`;
191
+ }
192
+ }
193
+ }
194
+ });
195
+ },
196
+ };
197
+ }
198
+ function apiPlugin() {
199
+ return {
200
+ name: 'taro:vite-h5-api',
201
+ enforce: 'post',
202
+ transform(code, id) {
203
+ return tslib.__awaiter(this, void 0, void 0, function* () {
204
+ const viteCompilerContext = yield getViteH5CompilerContext(this);
205
+ if (viteCompilerContext) {
206
+ const exts = Array.from(new Set(viteCompilerContext.frameworkExts.concat(helper.SCRIPT_EXT)));
207
+ if (id.startsWith(viteCompilerContext.sourceDir) && exts.some((ext) => id.includes(ext))) {
208
+ // @TODO 后续考虑使用 SWC 插件的方式实现
209
+ const result = yield core.transformAsync(code, {
210
+ filename: id,
211
+ plugins: [
212
+ [
213
+ require('babel-plugin-transform-taroapi'),
214
+ {
215
+ packageName: '@tarojs/taro',
216
+ definition: require(that.libraryDefinition)
217
+ },
218
+ ],
219
+ ],
220
+ });
221
+ return {
222
+ code: (result === null || result === void 0 ? void 0 : result.code) || code,
223
+ map: (result === null || result === void 0 ? void 0 : result.map) || null,
224
+ };
225
+ }
226
+ }
227
+ });
228
+ },
229
+ };
230
+ }
231
+ viteConfig.plugins.push(aliasPlugin());
232
+ viteConfig.plugins.push(injectLoaderMeta());
233
+ viteConfig.plugins.push(apiPlugin());
514
234
  });
515
235
  }
516
236
  }
@@ -519,8 +239,8 @@ var index = (ctx) => {
519
239
  ctx.registerPlatform({
520
240
  name: 'h5',
521
241
  useConfigName: 'h5',
522
- fn({ config }) {
523
- return __awaiter(this, void 0, void 0, function* () {
242
+ fn(_a) {
243
+ return tslib.__awaiter(this, arguments, void 0, function* ({ config }) {
524
244
  const program = new H5(ctx, config);
525
245
  yield program.start();
526
246
  });
@@ -528,7 +248,10 @@ var index = (ctx) => {
528
248
  });
529
249
  };
530
250
 
251
+ Object.defineProperty(exports, "resolveSync", {
252
+ enumerable: true,
253
+ get: function () { return helper.resolveSync; }
254
+ });
531
255
  exports.H5 = H5;
532
256
  exports.default = index;
533
- exports.resolveSync = resolveSync;
534
257
  //# sourceMappingURL=index.js.map