@tarojs/webpack5-runner 4.2.1-beta.2 → 4.2.1

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.
Files changed (32) hide show
  1. package/dist/plugins/BuildNativePlugin.js +11 -15
  2. package/dist/plugins/BuildNativePlugin.js.map +1 -1
  3. package/dist/plugins/HarmonyPlugin.js +1 -1
  4. package/dist/plugins/HarmonyPlugin.js.map +1 -1
  5. package/dist/plugins/MiniCompileModePlugin.js +4 -49
  6. package/dist/plugins/MiniCompileModePlugin.js.map +1 -1
  7. package/dist/plugins/MiniPlugin.js +56 -261
  8. package/dist/plugins/MiniPlugin.js.map +1 -1
  9. package/dist/plugins/TaroNormalModule.js +0 -16
  10. package/dist/plugins/TaroNormalModule.js.map +1 -1
  11. package/dist/plugins/TaroNormalModulesPlugin.js +6 -127
  12. package/dist/plugins/TaroNormalModulesPlugin.js.map +1 -1
  13. package/dist/plugins/TaroSingleEntryPlugin.js +1 -1
  14. package/dist/plugins/TaroSingleEntryPlugin.js.map +1 -1
  15. package/dist/template/comp.js +1 -2
  16. package/dist/utils/component.js +1 -2
  17. package/dist/utils/component.js.map +1 -1
  18. package/dist/webpack/H5WebpackPlugin.js +1 -1
  19. package/dist/webpack/H5WebpackPlugin.js.map +1 -1
  20. package/dist/webpack/HarmonyWebpackPlugin.js +1 -3
  21. package/dist/webpack/HarmonyWebpackPlugin.js.map +1 -1
  22. package/dist/webpack/MiniBaseConfig.js +0 -2
  23. package/dist/webpack/MiniBaseConfig.js.map +1 -1
  24. package/package.json +12 -12
  25. package/dist/plugins/AsyncSubPackagePlugin.js +0 -489
  26. package/dist/plugins/AsyncSubPackagePlugin.js.map +0 -1
  27. package/dist/plugins/SubPackageIndiePlugin.js +0 -1022
  28. package/dist/plugins/SubPackageIndiePlugin.js.map +0 -1
  29. package/dist/utils/asyncSubPackage.js +0 -106
  30. package/dist/utils/asyncSubPackage.js.map +0 -1
  31. package/dist/utils/forceCustomWrapper.js +0 -17
  32. package/dist/utils/forceCustomWrapper.js.map +0 -1
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -35,28 +12,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
35
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
13
  };
37
14
  Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.STYLE_ISOLATION_SHARED = exports.STYLE_ISOLATION_APPLY_SHARED = exports.customWrapperName = exports.baseCompName = void 0;
39
15
  const node_path_1 = __importDefault(require("node:path"));
40
16
  const helper_1 = require("@tarojs/helper");
41
17
  const loader_utils_1 = require("loader-utils");
42
- const tapable_1 = require("tapable");
43
18
  const EntryDependency_1 = __importDefault(require("webpack/lib/dependencies/EntryDependency"));
44
19
  const TaroSingleEntryDependency_1 = __importDefault(require("../dependencies/TaroSingleEntryDependency"));
45
20
  const prerender_1 = require("../prerender/prerender");
46
21
  const component_1 = require("../utils/component");
47
- const forceCustomWrapper_1 = require("../utils/forceCustomWrapper");
48
22
  const webpack_1 = require("../utils/webpack");
49
- const AsyncSubPackagePlugin_1 = __importDefault(require("./AsyncSubPackagePlugin"));
50
- const SubPackageIndiePlugin_1 = __importStar(require("./SubPackageIndiePlugin"));
51
23
  const TaroLoadChunksPlugin_1 = __importDefault(require("./TaroLoadChunksPlugin"));
52
24
  const TaroNormalModulesPlugin_1 = __importDefault(require("./TaroNormalModulesPlugin"));
53
25
  const TaroSingleEntryPlugin_1 = __importDefault(require("./TaroSingleEntryPlugin"));
54
- exports.baseCompName = 'comp';
55
- exports.customWrapperName = 'custom-wrapper';
26
+ const baseCompName = 'comp';
27
+ const customWrapperName = 'custom-wrapper';
56
28
  const PLUGIN_NAME = 'TaroMiniPlugin';
57
29
  const CHILD_COMPILER_TAG = 'child';
58
- exports.STYLE_ISOLATION_APPLY_SHARED = 'apply-shared';
59
- exports.STYLE_ISOLATION_SHARED = 'shared';
60
30
  function isLoaderExist(loaders, loaderName) {
61
31
  return loaders.some(item => item.loader === loaderName);
62
32
  }
@@ -76,9 +46,6 @@ class TaroMiniPlugin {
76
46
  this.dependencies = new Map();
77
47
  this.pageLoaderName = '@tarojs/taro-loader/lib/page';
78
48
  this.independentPackages = new Map();
79
- this.asyncSubPackagePlugin = null;
80
- this.subPackageIndiePlugin = null;
81
- this.forceCustomWrapperDefineDefinitions = null;
82
49
  const { combination } = options;
83
50
  const miniBuildConfig = combination.config;
84
51
  const { template, baseLevel = 16, experimental } = miniBuildConfig;
@@ -102,22 +69,6 @@ class TaroMiniPlugin {
102
69
  hot: options.hot,
103
70
  loaderMeta: options.loaderMeta || {},
104
71
  };
105
- // 初始化扩展钩子
106
- this.hooks = {
107
- modifyEntries: new tapable_1.SyncWaterfallHook(['entries']),
108
- modifyChunkRequire: new tapable_1.SyncWaterfallHook(['result', 'chunkId', 'miniType']),
109
- afterResolveModule: new tapable_1.SyncHook(['resolveData']),
110
- compileExtraEntries: new tapable_1.SyncHook(['compiler', 'compilation', 'promises']),
111
- modifySkipRootTemplates: new tapable_1.SyncWaterfallHook(['skip']),
112
- generateExtraFiles: new tapable_1.SyncWaterfallHook(['customWrapperRoots', 'compilation', 'compiler']),
113
- modifyPageConfig: new tapable_1.SyncWaterfallHook(['context', 'page', 'customWrapperRoots']),
114
- modifyComponentConfig: new tapable_1.SyncHook(['context', 'customWrapperRoots']),
115
- afterGenerateFiles: new tapable_1.SyncHook(['compilation', 'compiler']),
116
- optimizeAssets: new tapable_1.SyncHook(['compilation']),
117
- modifyConfig: new tapable_1.SyncWaterfallHook(['config', 'componentName']),
118
- modifyStyleImport: new tapable_1.SyncWaterfallHook(['context', 'page']),
119
- modifyShouldProcessStyles: new tapable_1.SyncWaterfallHook(['shouldProcess']),
120
- };
121
72
  if (template.isSupportRecursive === false && baseLevel > 0) {
122
73
  template.baseLevel = baseLevel;
123
74
  }
@@ -148,17 +99,11 @@ class TaroMiniPlugin {
148
99
  apply(compiler) {
149
100
  this.context = compiler.context;
150
101
  this.appEntry = this.getAppEntry(compiler);
151
- if (this.options.newBlended) {
152
- this.subPackageIndiePlugin = new SubPackageIndiePlugin_1.default(this);
153
- this.subPackageIndiePlugin.apply();
154
- }
155
102
  const { commonChunks, combination, framework, isBuildPlugin, newBlended, } = this.options;
156
103
  const { addChunkPages, onCompilerMake, modifyBuildAssets, onParseCreateElement, } = combination.config;
157
104
  /** build mode */
158
105
  compiler.hooks.run.tapAsync(PLUGIN_NAME, this.tryAsync((compiler) => __awaiter(this, void 0, void 0, function* () {
159
106
  yield this.run(compiler);
160
- this.applyForceCustomWrapperDefine(compiler);
161
- this.applyAsyncSubPackagePlugin(compiler);
162
107
  new TaroLoadChunksPlugin_1.default({
163
108
  commonChunks: commonChunks,
164
109
  isBuildPlugin,
@@ -175,8 +120,6 @@ class TaroMiniPlugin {
175
120
  this.isWatch = true;
176
121
  }
177
122
  yield this.run(compiler);
178
- this.applyForceCustomWrapperDefine(compiler);
179
- this.applyAsyncSubPackagePlugin(compiler);
180
123
  if (!this.loadChunksPlugin) {
181
124
  this.loadChunksPlugin = new TaroLoadChunksPlugin_1.default({
182
125
  commonChunks: commonChunks,
@@ -194,7 +137,6 @@ class TaroMiniPlugin {
194
137
  const dependencies = this.dependencies;
195
138
  const promises = [];
196
139
  this.compileIndependentPages(compiler, compilation, dependencies, promises);
197
- this.hooks.compileExtraEntries.call(compiler, compilation, promises);
198
140
  dependencies.forEach(dep => {
199
141
  promises.push(new Promise((resolve, reject) => {
200
142
  compilation.addEntry(this.options.sourceDir, dep, Object.assign({ name: dep.name }, dep.options), err => err ? reject(err) : resolve(null));
@@ -207,11 +149,6 @@ class TaroMiniPlugin {
207
149
  /** For Webpack compilation get factory from compilation.dependencyFactories by denpendence's constructor */
208
150
  compilation.dependencyFactories.set(EntryDependency_1.default, normalModuleFactory);
209
151
  compilation.dependencyFactories.set(TaroSingleEntryDependency_1.default, normalModuleFactory);
210
- if (this.options.newBlended) {
211
- normalModuleFactory.hooks.afterResolve.tap(PLUGIN_NAME, (resolveData) => {
212
- this.hooks.afterResolveModule.call(resolveData);
213
- });
214
- }
215
152
  /**
216
153
  * webpack NormalModule 在 runLoaders 真正解析资源的前一刻,
217
154
  * 往 NormalModule.loaders 中插入对应的 Taro Loader
@@ -355,10 +292,6 @@ class TaroMiniPlugin {
355
292
  let source;
356
293
  const id = (0, webpack_1.getChunkIdOrName)(chunk);
357
294
  const { miniType } = entryModule;
358
- const modifyResult = this.hooks.modifyChunkRequire.call({ source: modules, handled: false }, id, miniType);
359
- if (modifyResult === null || modifyResult === void 0 ? void 0 : modifyResult.handled) {
360
- return modifyResult.source;
361
- }
362
295
  const entryChunk = [{ name: 'app' }];
363
296
  // 所有模块都依赖app.js,确保@tarojs\plugin-platform-xxx\dist\runtime.js先于@tarojs/runtime执行,避免Taro API未被初始化
364
297
  if (this.nativeComponents.has(id) || miniType === helper_1.META_TYPE.STATIC) {
@@ -367,8 +300,7 @@ class TaroMiniPlugin {
367
300
  source = (0, webpack_1.addRequireToSource)(id, modules, v);
368
301
  }
369
302
  });
370
- // 如果没有依赖需要注入,返回原始模块
371
- return source || modules;
303
+ return source;
372
304
  }
373
305
  else if (miniType === helper_1.META_TYPE.PAGE) {
374
306
  return (0, webpack_1.addRequireToSource)(id, modules, entryChunk);
@@ -377,23 +309,6 @@ class TaroMiniPlugin {
377
309
  });
378
310
  });
379
311
  }
380
- /**
381
- * 初始化异步分包插件。
382
- * MiniPlugin 仅作为桥接,具体的 babel 注入、chunk 处理和 app.json 注册由 AsyncSubPackagePlugin 承担。
383
- */
384
- applyAsyncSubPackagePlugin(compiler) {
385
- if (!this.subPackageIndiePlugin)
386
- return;
387
- const asyncRootMap = this.subPackageIndiePlugin.getAsyncSubPackageRootMap();
388
- if (asyncRootMap.size === 0)
389
- return;
390
- if (!this.asyncSubPackagePlugin) {
391
- this.asyncSubPackagePlugin = new AsyncSubPackagePlugin_1.default(this);
392
- }
393
- this.asyncSubPackagePlugin.updateAsyncRootMap(asyncRootMap);
394
- this.asyncSubPackagePlugin.updateAsyncRuntimeRoots(this.subPackageIndiePlugin.getAsyncSubPackageRuntimeRoots());
395
- this.asyncSubPackagePlugin.apply(compiler);
396
- }
397
312
  /**
398
313
  * 根据 webpack entry 配置获取入口文件路径
399
314
  * @returns app 入口文件路径
@@ -439,8 +354,6 @@ class TaroMiniPlugin {
439
354
  */
440
355
  run(compiler) {
441
356
  return __awaiter(this, void 0, void 0, function* () {
442
- var _a;
443
- (_a = this.subPackageIndiePlugin) === null || _a === void 0 ? void 0 : _a.invalidateRunCache();
444
357
  if (this.options.isBuildPlugin) {
445
358
  this.getPluginFiles();
446
359
  this.getConfigFiles(compiler);
@@ -566,12 +479,12 @@ class TaroMiniPlugin {
566
479
  }
567
480
  if (!this.options.template.isSupportRecursive) {
568
481
  pluginJSON.publicComponents = Object.assign({}, publicComponents, {
569
- [exports.baseCompName]: exports.baseCompName
482
+ [baseCompName]: baseCompName
570
483
  });
571
484
  }
572
485
  if (isUsingCustomWrapper) {
573
486
  pluginJSON.publicComponents = Object.assign({}, publicComponents, {
574
- [exports.customWrapperName]: exports.customWrapperName
487
+ [customWrapperName]: customWrapperName
575
488
  });
576
489
  }
577
490
  }
@@ -700,11 +613,8 @@ class TaroMiniPlugin {
700
613
  */
701
614
  addEntry(entryPath, entryName, entryType, options = {}) {
702
615
  let dep;
703
- // 对于 STATIC 类型(如 comp/custom-wrapper),使用 entryName 作为 key 的一部分
704
- // 这允许同一个模板文件被多次添加为不同名称的入口
705
- const depKey = entryType === helper_1.META_TYPE.STATIC ? `${entryPath}#${entryName}` : entryPath;
706
- if (this.dependencies.has(depKey)) {
707
- dep = this.dependencies.get(depKey);
616
+ if (this.dependencies.has(entryPath)) {
617
+ dep = this.dependencies.get(entryPath);
708
618
  dep.name = entryName;
709
619
  dep.loc = { name: entryName };
710
620
  dep.request = entryPath;
@@ -715,7 +625,7 @@ class TaroMiniPlugin {
715
625
  else {
716
626
  dep = new TaroSingleEntryDependency_1.default(entryPath, entryName, { name: entryName }, entryType, options);
717
627
  }
718
- this.dependencies.set(depKey, dep);
628
+ this.dependencies.set(entryPath, dep);
719
629
  }
720
630
  /**
721
631
  * 在 this.dependencies 中新增或修改 app、模板组件、页面、组件等资源模块
@@ -723,17 +633,10 @@ class TaroMiniPlugin {
723
633
  addEntries() {
724
634
  const { template } = this.options;
725
635
  this.addEntry(this.appEntry, 'app', helper_1.META_TYPE.ENTRY);
726
- const entryFlags = this.hooks.modifyEntries.call({
727
- skipRootComp: false,
728
- skipRootWrapper: false,
729
- });
730
- if (!template.isSupportRecursive && !entryFlags.skipRootComp) {
636
+ if (!template.isSupportRecursive) {
731
637
  this.addEntry(node_path_1.default.resolve(__dirname, '..', 'template/comp'), 'comp', helper_1.META_TYPE.STATIC);
732
638
  }
733
- if (!entryFlags.skipRootWrapper) {
734
- this.addEntry(node_path_1.default.resolve(__dirname, '..', 'template/custom-wrapper'), 'custom-wrapper', helper_1.META_TYPE.STATIC);
735
- }
736
- // subPackageIndie 下的 comp/custom-wrapper 统一走独立子编译器,避免被主编译的公共 chunk 共享
639
+ this.addEntry(node_path_1.default.resolve(__dirname, '..', 'template/custom-wrapper'), 'custom-wrapper', helper_1.META_TYPE.STATIC);
737
640
  this.pages.forEach(item => {
738
641
  if (item.isNative) {
739
642
  this.addEntry(item.path, item.name, helper_1.META_TYPE.NORMAL, { isNativePage: true });
@@ -763,39 +666,6 @@ class TaroMiniPlugin {
763
666
  }
764
667
  });
765
668
  }
766
- computeForceCustomWrapperForWebpackMainComp() {
767
- var _a;
768
- if (this.options.template.isSupportRecursive)
769
- return false;
770
- const independentPaths = new Set();
771
- this.independentPackages.forEach(({ pages }) => {
772
- pages.forEach(p => independentPaths.add(p));
773
- });
774
- for (const page of this.pages) {
775
- if (page.isNative || independentPaths.has(page.path))
776
- continue;
777
- const content = (_a = this.filesConfig[this.getConfigFilePath(page.name)]) === null || _a === void 0 ? void 0 : _a.content;
778
- if (content === null || content === void 0 ? void 0 : content.forceCustomWrapper)
779
- return true;
780
- }
781
- return false;
782
- }
783
- computeForceCustomWrapperForIndieRoot(pages) {
784
- return (0, forceCustomWrapper_1.computeForceCustomWrapperForIndependentPackage)(pages, this.pages, this.filesConfig, (p) => this.getConfigFilePath(p));
785
- }
786
- applyForceCustomWrapperDefine(compiler) {
787
- if (this.options.template.isSupportRecursive)
788
- return;
789
- const value = JSON.stringify(this.computeForceCustomWrapperForWebpackMainComp());
790
- if (!this.forceCustomWrapperDefineDefinitions) {
791
- this.forceCustomWrapperDefineDefinitions = {
792
- TARO_FORCE_CUSTOM_WRAPPER: value
793
- };
794
- new compiler.webpack.DefinePlugin(this.forceCustomWrapperDefineDefinitions).apply(compiler);
795
- return;
796
- }
797
- this.forceCustomWrapperDefineDefinitions.TARO_FORCE_CUSTOM_WRAPPER = value;
798
- }
799
669
  replaceExt(file, ext) {
800
670
  return node_path_1.default.join(node_path_1.default.dirname(file), node_path_1.default.basename(file, node_path_1.default.extname(file)) + `${ext}`);
801
671
  }
@@ -955,7 +825,7 @@ class TaroMiniPlugin {
955
825
  filename: `[name]${this.options.fileType.style}`,
956
826
  chunkFilename: `[name]${this.options.fileType.style}`
957
827
  }).apply(childCompiler);
958
- new compiler.webpack.DefinePlugin(Object.assign(Object.assign({}, this.options.constantsReplaceList), { TARO_FORCE_CUSTOM_WRAPPER: JSON.stringify(this.computeForceCustomWrapperForIndieRoot(pages)) })).apply(childCompiler);
828
+ new compiler.webpack.DefinePlugin(this.options.constantsReplaceList).apply(childCompiler);
959
829
  if (compiler.options.optimization) {
960
830
  new SplitChunksPlugin({
961
831
  chunks: 'all',
@@ -1095,12 +965,6 @@ class TaroMiniPlugin {
1095
965
  usingComponents[key] = match ? `${node_path_1.default.sep}${match[0]}` : compPath;
1096
966
  }
1097
967
  }
1098
- cloneThirdPartyComponent(thirdPartyComponents, componentName) {
1099
- const attrs = component_1.componentConfig.thirdPartyComponents.get(componentName);
1100
- if (!attrs || thirdPartyComponents.has(componentName))
1101
- return;
1102
- thirdPartyComponents.set(componentName, new Set(attrs));
1103
- }
1104
968
  /** 生成小程序独立分包的相关文件 */
1105
969
  generateIndependentMiniFiles(compilation, compiler) {
1106
970
  return __awaiter(this, void 0, void 0, function* () {
@@ -1117,27 +981,24 @@ class TaroMiniPlugin {
1117
981
  this.generateTemplateFile(compilation, compiler, `${name}/${baseTemplateName}`, template.buildTemplate, component_1.componentConfig);
1118
982
  if (!template.isSupportRecursive) {
1119
983
  // 如微信、QQ 不支持递归模版的小程序,需要使用自定义组件协助递归
1120
- const compConfig = {
984
+ this.generateConfigFile(compilation, compiler, `${name}/${baseCompName}`, {
1121
985
  component: true,
1122
- styleIsolation: exports.STYLE_ISOLATION_APPLY_SHARED,
986
+ styleIsolation: 'apply-shared',
1123
987
  usingComponents: {
1124
- [exports.baseCompName]: `./${exports.baseCompName}`
988
+ [baseCompName]: `./${baseCompName}`,
989
+ [customWrapperName]: `./${customWrapperName}`
1125
990
  }
1126
- };
1127
- if (isUsingCustomWrapper) {
1128
- compConfig.usingComponents[exports.customWrapperName] = `./${exports.customWrapperName}`;
1129
- }
1130
- this.generateConfigFile(compilation, compiler, `${name}/${exports.baseCompName}`, compConfig);
1131
- this.generateTemplateFile(compilation, compiler, `${name}/${exports.baseCompName}`, template.buildBaseComponentTemplate, this.options.fileType.templ);
991
+ });
992
+ this.generateTemplateFile(compilation, compiler, `${name}/${baseCompName}`, template.buildBaseComponentTemplate, this.options.fileType.templ);
1132
993
  }
1133
- this.generateConfigFile(compilation, compiler, `${name}/${exports.customWrapperName}`, {
994
+ this.generateConfigFile(compilation, compiler, `${name}/${customWrapperName}`, {
1134
995
  component: true,
1135
- styleIsolation: exports.STYLE_ISOLATION_APPLY_SHARED,
996
+ styleIsolation: 'apply-shared',
1136
997
  usingComponents: {
1137
- [exports.customWrapperName]: `./${exports.customWrapperName}`
998
+ [customWrapperName]: `./${customWrapperName}`
1138
999
  }
1139
1000
  });
1140
- this.generateTemplateFile(compilation, compiler, `${name}/${exports.customWrapperName}`, template.buildCustomComponentTemplate, this.options.fileType.templ);
1001
+ this.generateTemplateFile(compilation, compiler, `${name}/${customWrapperName}`, template.buildCustomComponentTemplate, this.options.fileType.templ);
1141
1002
  this.generateXSFile(compilation, compiler, `${name}/utils`);
1142
1003
  });
1143
1004
  this.pages.forEach(page => {
@@ -1160,14 +1021,14 @@ class TaroMiniPlugin {
1160
1021
  this.generateTemplateFile(compilation, compiler, page.path, template.buildPageTemplate, importBaseTemplatePath, config);
1161
1022
  }
1162
1023
  if (config) {
1163
- const importBaseCompPath = (0, helper_1.promoteRelativePath)(node_path_1.default.relative(page.path, node_path_1.default.join(sourceDir, independentName, this.getTargetFilePath(exports.baseCompName, ''))));
1164
- const importCustomWrapperPath = (0, helper_1.promoteRelativePath)(node_path_1.default.relative(page.path, node_path_1.default.join(sourceDir, independentName, this.getTargetFilePath(exports.customWrapperName, ''))));
1024
+ const importBaseCompPath = (0, helper_1.promoteRelativePath)(node_path_1.default.relative(page.path, node_path_1.default.join(sourceDir, independentName, this.getTargetFilePath(baseCompName, ''))));
1025
+ const importCustomWrapperPath = (0, helper_1.promoteRelativePath)(node_path_1.default.relative(page.path, node_path_1.default.join(sourceDir, independentName, this.getTargetFilePath(customWrapperName, ''))));
1165
1026
  config.content.usingComponents = Object.assign({}, config.content.usingComponents);
1166
1027
  if (isUsingCustomWrapper) {
1167
- config.content.usingComponents[exports.customWrapperName] = importCustomWrapperPath;
1028
+ config.content.usingComponents[customWrapperName] = importCustomWrapperPath;
1168
1029
  }
1169
1030
  if (!template.isSupportRecursive && !page.isNative) {
1170
- config.content.usingComponents[exports.baseCompName] = importBaseCompPath;
1031
+ config.content.usingComponents[baseCompName] = importBaseCompPath;
1171
1032
  }
1172
1033
  this.generateConfigFile(compilation, compiler, page.path, config.content);
1173
1034
  }
@@ -1182,8 +1043,6 @@ class TaroMiniPlugin {
1182
1043
  const { modifyMiniConfigs } = combination.config;
1183
1044
  const baseTemplateName = 'base';
1184
1045
  const isUsingCustomWrapper = component_1.componentConfig.thirdPartyComponents.has('custom-wrapper');
1185
- let subPackageIndieCustomWrapperRoots = new Set();
1186
- compilation[SubPackageIndiePlugin_1.subPackageIndieCustomWrapperRootsKey] = subPackageIndieCustomWrapperRoots;
1187
1046
  /**
1188
1047
  * 与原生小程序混写时解析模板与样式
1189
1048
  */
@@ -1203,55 +1062,47 @@ class TaroMiniPlugin {
1203
1062
  const appConfigName = node_path_1.default.basename(appConfigPath).replace(node_path_1.default.extname(appConfigPath), '');
1204
1063
  this.generateConfigFile(compilation, compiler, this.appEntry, this.filesConfig[appConfigName].content);
1205
1064
  }
1206
- let skipRootTemplates = false;
1207
- skipRootTemplates = this.hooks.modifySkipRootTemplates.call(skipRootTemplates);
1208
- if (!template.isSupportRecursive && !skipRootTemplates) {
1065
+ if (!template.isSupportRecursive) {
1209
1066
  // 如微信、QQ 不支持递归模版的小程序,需要使用自定义组件协助递归
1210
- this.generateTemplateFile(compilation, compiler, exports.baseCompName, template.buildBaseComponentTemplate, this.options.fileType.templ);
1067
+ this.generateTemplateFile(compilation, compiler, baseCompName, template.buildBaseComponentTemplate, this.options.fileType.templ);
1211
1068
  const baseCompConfig = {
1212
1069
  component: true,
1213
- styleIsolation: exports.STYLE_ISOLATION_APPLY_SHARED,
1070
+ styleIsolation: 'apply-shared',
1214
1071
  usingComponents: {
1215
- [exports.baseCompName]: `./${exports.baseCompName}`
1072
+ [baseCompName]: `./${baseCompName}`
1216
1073
  }
1217
1074
  };
1218
1075
  if (isUsingCustomWrapper) {
1219
- baseCompConfig.usingComponents[exports.customWrapperName] = `./${exports.customWrapperName}`;
1220
- this.generateConfigFile(compilation, compiler, exports.customWrapperName, {
1076
+ baseCompConfig.usingComponents[customWrapperName] = `./${customWrapperName}`;
1077
+ this.generateConfigFile(compilation, compiler, customWrapperName, {
1221
1078
  component: true,
1222
- styleIsolation: exports.STYLE_ISOLATION_APPLY_SHARED,
1079
+ styleIsolation: 'apply-shared',
1223
1080
  usingComponents: {
1224
- [exports.baseCompName]: `./${exports.baseCompName}`,
1225
- [exports.customWrapperName]: `./${exports.customWrapperName}`
1081
+ [baseCompName]: `./${baseCompName}`,
1082
+ [customWrapperName]: `./${customWrapperName}`
1226
1083
  }
1227
1084
  });
1228
1085
  }
1229
- this.generateConfigFile(compilation, compiler, exports.baseCompName, baseCompConfig);
1086
+ this.generateConfigFile(compilation, compiler, baseCompName, baseCompConfig);
1230
1087
  }
1231
- else if (!skipRootTemplates) {
1088
+ else {
1232
1089
  if (isUsingCustomWrapper) {
1233
- this.generateConfigFile(compilation, compiler, exports.customWrapperName, {
1090
+ this.generateConfigFile(compilation, compiler, customWrapperName, {
1234
1091
  component: true,
1235
- styleIsolation: exports.STYLE_ISOLATION_APPLY_SHARED,
1092
+ styleIsolation: 'apply-shared',
1236
1093
  usingComponents: {
1237
- [exports.customWrapperName]: `./${exports.customWrapperName}`
1094
+ [customWrapperName]: `./${customWrapperName}`
1238
1095
  }
1239
1096
  });
1240
1097
  }
1241
1098
  }
1242
- // 当配置了 mainPackageRoot 时,跳过根目录 base.wxml 和 utils.wxs 的生成
1243
- if (!skipRootTemplates) {
1244
- this.generateTemplateFile(compilation, compiler, baseTemplateName, template.buildTemplate, component_1.componentConfig);
1245
- isUsingCustomWrapper && this.generateTemplateFile(compilation, compiler, exports.customWrapperName, template.buildCustomComponentTemplate, this.options.fileType.templ);
1246
- this.generateXSFile(compilation, compiler, 'utils');
1247
- }
1248
- subPackageIndieCustomWrapperRoots = this.hooks.generateExtraFiles.call(subPackageIndieCustomWrapperRoots, compilation, compiler);
1249
- compilation[SubPackageIndiePlugin_1.subPackageIndieCustomWrapperRootsKey] = subPackageIndieCustomWrapperRoots;
1099
+ this.generateTemplateFile(compilation, compiler, baseTemplateName, template.buildTemplate, component_1.componentConfig);
1100
+ isUsingCustomWrapper && this.generateTemplateFile(compilation, compiler, customWrapperName, template.buildCustomComponentTemplate, this.options.fileType.templ);
1101
+ this.generateXSFile(compilation, compiler, 'utils');
1250
1102
  this.components.forEach(component => {
1251
1103
  const importBaseTemplatePath = (0, helper_1.promoteRelativePath)(node_path_1.default.relative(component.path, node_path_1.default.join(sourceDir, isBuildPlugin ? 'plugin' : '', this.getTemplatePath(baseTemplateName))));
1252
1104
  const config = this.filesConfig[this.getConfigFilePath(component.name)];
1253
1105
  if (config) {
1254
- this.hooks.modifyComponentConfig.call({ config, component }, subPackageIndieCustomWrapperRoots);
1255
1106
  this.generateConfigFile(compilation, compiler, component.path, config.content);
1256
1107
  }
1257
1108
  if (!component.isNative) {
@@ -1259,46 +1110,31 @@ class TaroMiniPlugin {
1259
1110
  }
1260
1111
  });
1261
1112
  this.pages.forEach(page => {
1262
- let importBaseTemplatePath = (0, helper_1.promoteRelativePath)(node_path_1.default.relative(page.path, node_path_1.default.join(sourceDir, isBuildPlugin ? 'plugin' : '', this.getTemplatePath(baseTemplateName))));
1113
+ const importBaseTemplatePath = (0, helper_1.promoteRelativePath)(node_path_1.default.relative(page.path, node_path_1.default.join(sourceDir, isBuildPlugin ? 'plugin' : '', this.getTemplatePath(baseTemplateName))));
1263
1114
  const config = this.filesConfig[this.getConfigFilePath(page.name)];
1264
1115
  // pages 里面会混合独立分包的,在这里需要过滤一下,避免重复生成 assets
1265
1116
  const isIndependent = !!this.getIndependentPackage(page.path);
1266
1117
  if (isIndependent)
1267
1118
  return;
1268
1119
  // 生成页面模板需要在生成页面配置之前,因为会依赖到页面配置的部分内容
1269
- let importBaseCompPath = (0, helper_1.promoteRelativePath)(node_path_1.default.relative(page.path, node_path_1.default.join(sourceDir, isBuildPlugin ? 'plugin' : '', this.getTargetFilePath(exports.baseCompName, ''))));
1270
- let importCustomWrapperPath = (0, helper_1.promoteRelativePath)(node_path_1.default.relative(page.path, node_path_1.default.join(sourceDir, isBuildPlugin ? 'plugin' : '', this.getTargetFilePath(exports.customWrapperName, ''))));
1271
- let isPageRecursiveDisabled = false;
1272
- let shouldUseCustomWrapper = isUsingCustomWrapper;
1273
- const pageConfigContext = this.hooks.modifyPageConfig.call({
1274
- importBaseTemplatePath,
1275
- importBaseCompPath,
1276
- importCustomWrapperPath,
1277
- shouldUseCustomWrapper,
1278
- isPageRecursiveDisabled,
1279
- }, page, subPackageIndieCustomWrapperRoots);
1280
- importBaseTemplatePath = pageConfigContext.importBaseTemplatePath;
1281
- importBaseCompPath = pageConfigContext.importBaseCompPath;
1282
- importCustomWrapperPath = pageConfigContext.importCustomWrapperPath;
1283
- shouldUseCustomWrapper = pageConfigContext.shouldUseCustomWrapper;
1284
- isPageRecursiveDisabled = pageConfigContext.isPageRecursiveDisabled;
1285
1120
  if (!page.isNative) {
1286
1121
  this.generateTemplateFile(compilation, compiler, page.path, template.buildPageTemplate, importBaseTemplatePath, config);
1287
1122
  }
1288
1123
  if (config) {
1124
+ const importBaseCompPath = (0, helper_1.promoteRelativePath)(node_path_1.default.relative(page.path, node_path_1.default.join(sourceDir, isBuildPlugin ? 'plugin' : '', this.getTargetFilePath(baseCompName, ''))));
1125
+ const importCustomWrapperPath = (0, helper_1.promoteRelativePath)(node_path_1.default.relative(page.path, node_path_1.default.join(sourceDir, isBuildPlugin ? 'plugin' : '', this.getTargetFilePath(customWrapperName, ''))));
1289
1126
  config.content.usingComponents = Object.assign({}, config.content.usingComponents);
1290
- if (shouldUseCustomWrapper) {
1291
- config.content.usingComponents[exports.customWrapperName] = importCustomWrapperPath;
1127
+ if (isUsingCustomWrapper) {
1128
+ config.content.usingComponents[customWrapperName] = importCustomWrapperPath;
1292
1129
  }
1293
- if (!template.isSupportRecursive && !page.isNative && !isPageRecursiveDisabled) {
1294
- config.content.usingComponents[exports.baseCompName] = importBaseCompPath;
1130
+ if (!template.isSupportRecursive && !page.isNative) {
1131
+ config.content.usingComponents[baseCompName] = importBaseCompPath;
1295
1132
  }
1296
1133
  this.generateConfigFile(compilation, compiler, page.path, config.content);
1297
1134
  }
1298
1135
  });
1299
1136
  this.generateTabBarFiles(compilation, compiler);
1300
1137
  this.injectCommonStyles(compilation, compiler);
1301
- this.hooks.afterGenerateFiles.call(compilation, compiler);
1302
1138
  if (this.themeLocation) {
1303
1139
  this.generateDarkModeFile(compilation, compiler);
1304
1140
  }
@@ -1331,15 +1167,12 @@ class TaroMiniPlugin {
1331
1167
  delete compilation.assets[assetPath];
1332
1168
  }
1333
1169
  });
1334
- this.hooks.optimizeAssets.call(compilation);
1335
1170
  });
1336
1171
  }
1337
1172
  generateConfigFile(compilation, compiler, filePath, config) {
1338
1173
  const { RawSource } = compiler.webpack.sources;
1339
1174
  const fileConfigName = this.getConfigPath(this.getComponentName(filePath));
1340
- const componentName = this.getComponentName(filePath);
1341
- config = this.hooks.modifyConfig.call(config, componentName);
1342
- const unofficialConfigs = ['enableShareAppMessage', 'enableShareTimeline', 'enablePageMeta', 'components', 'forceCustomWrapper'];
1175
+ const unofficialConfigs = ['enableShareAppMessage', 'enableShareTimeline', 'enablePageMeta', 'components'];
1343
1176
  unofficialConfigs.forEach(item => {
1344
1177
  delete config[item];
1345
1178
  });
@@ -1485,21 +1318,12 @@ class TaroMiniPlugin {
1485
1318
  });
1486
1319
  });
1487
1320
  }
1488
- // 判断是否需要处理样式:有 common chunks 或者有 app.wxss(可被扩展插件修改)
1489
- const hasAppStyle = !!assets[appStyle];
1490
- let shouldProcessStyles = commons.size() > 0;
1491
- if (!hasAppStyle) {
1492
- shouldProcessStyles = false;
1493
- }
1494
- shouldProcessStyles = this.hooks.modifyShouldProcessStyles.call(shouldProcessStyles);
1495
- if (shouldProcessStyles) {
1321
+ if (commons.size() > 0) {
1496
1322
  const APP_STYLE_NAME = 'app-origin' + styleExt;
1497
1323
  assets[APP_STYLE_NAME] = new ConcatSource(originSource);
1498
1324
  const source = new ConcatSource('');
1499
1325
  source.add(`@import ${JSON.stringify((0, loader_utils_1.urlToRequest)(APP_STYLE_NAME))};`);
1500
- if (commons.size() > 0) {
1501
- source.add(commons);
1502
- }
1326
+ source.add(commons);
1503
1327
  source.add('\n');
1504
1328
  assets[appStyle] = source;
1505
1329
  if (newBlended) {
@@ -1515,43 +1339,14 @@ class TaroMiniPlugin {
1515
1339
  }
1516
1340
  const source = new ConcatSource('');
1517
1341
  const originSource = assets[pageStyle];
1518
- const styleImportContext = this.hooks.modifyStyleImport.call({
1519
- importStatement: '',
1520
- shouldSkip: false,
1521
- isMainPackageRoot: false,
1522
- }, page);
1523
- if (styleImportContext.shouldSkip) {
1524
- // no-op
1525
- }
1526
- else if (styleImportContext.importStatement) {
1527
- source.add(styleImportContext.importStatement);
1528
- }
1529
- else {
1530
- componentCommons.forEach(item => {
1531
- source.add(`@import ${JSON.stringify((0, loader_utils_1.urlToRequest)(node_path_1.default.posix.relative(node_path_1.default.dirname(pageStyle), item)))};\n`);
1532
- });
1533
- }
1342
+ componentCommons.forEach(item => {
1343
+ source.add(`@import ${JSON.stringify((0, loader_utils_1.urlToRequest)(node_path_1.default.posix.relative(node_path_1.default.dirname(pageStyle), item)))};\n`);
1344
+ });
1534
1345
  source.add(originSource);
1535
1346
  assets[pageStyle] = source;
1536
1347
  }
1537
1348
  else {
1538
- // 普通页面(非本地化组件)
1539
- const styleImportContext = this.hooks.modifyStyleImport.call({
1540
- importStatement: '',
1541
- shouldSkip: false,
1542
- isMainPackageRoot: false,
1543
- }, page);
1544
- if (styleImportContext.importStatement) {
1545
- const source = new ConcatSource('');
1546
- if (pageStyle in assets) {
1547
- source.add(assets[pageStyle]);
1548
- }
1549
- const importSource = new ConcatSource('');
1550
- importSource.add(styleImportContext.importStatement);
1551
- importSource.add(source);
1552
- assets[pageStyle] = importSource;
1553
- }
1554
- else if (pageStyle in assets) {
1349
+ if (pageStyle in assets) {
1555
1350
  const source = new ConcatSource('');
1556
1351
  const originSource = assets[pageStyle];
1557
1352
  source.add(`@import ${JSON.stringify((0, loader_utils_1.urlToRequest)(node_path_1.default.posix.relative(node_path_1.default.dirname(pageStyle), 'app' + styleExt)))};\n`);