@tarojs/webpack5-runner 4.1.12-beta.4 → 4.1.12-beta.40
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/plugins/HarmonyPlugin.js +1 -1
- package/dist/plugins/HarmonyPlugin.js.map +1 -1
- package/dist/plugins/MiniCompileModePlugin.js +49 -4
- package/dist/plugins/MiniCompileModePlugin.js.map +1 -1
- package/dist/plugins/MiniPlugin.js +232 -56
- package/dist/plugins/MiniPlugin.js.map +1 -1
- package/dist/plugins/SubPackageIndiePlugin.js +838 -0
- package/dist/plugins/SubPackageIndiePlugin.js.map +1 -0
- package/dist/plugins/TaroNormalModule.js +16 -0
- package/dist/plugins/TaroNormalModule.js.map +1 -1
- package/dist/plugins/TaroNormalModulesPlugin.js +127 -6
- package/dist/plugins/TaroNormalModulesPlugin.js.map +1 -1
- package/dist/plugins/TaroSingleEntryPlugin.js +1 -1
- package/dist/plugins/TaroSingleEntryPlugin.js.map +1 -1
- package/dist/template/comp.js +2 -1
- package/dist/utils/component.js +2 -1
- package/dist/utils/component.js.map +1 -1
- package/dist/utils/forceCustomWrapper.js +17 -0
- package/dist/utils/forceCustomWrapper.js.map +1 -0
- package/dist/webpack/HarmonyWebpackPlugin.js +3 -1
- package/dist/webpack/HarmonyWebpackPlugin.js.map +1 -1
- package/package.json +12 -12
|
@@ -1,4 +1,27 @@
|
|
|
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
|
+
};
|
|
2
25
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
26
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
27
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -12,21 +35,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
36
|
};
|
|
14
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.STYLE_ISOLATION_SHARED = exports.STYLE_ISOLATION_APPLY_SHARED = exports.customWrapperName = exports.baseCompName = void 0;
|
|
15
39
|
const node_path_1 = __importDefault(require("node:path"));
|
|
16
40
|
const helper_1 = require("@tarojs/helper");
|
|
17
41
|
const loader_utils_1 = require("loader-utils");
|
|
42
|
+
const tapable_1 = require("tapable");
|
|
18
43
|
const EntryDependency_1 = __importDefault(require("webpack/lib/dependencies/EntryDependency"));
|
|
19
44
|
const TaroSingleEntryDependency_1 = __importDefault(require("../dependencies/TaroSingleEntryDependency"));
|
|
20
45
|
const prerender_1 = require("../prerender/prerender");
|
|
21
46
|
const component_1 = require("../utils/component");
|
|
47
|
+
const forceCustomWrapper_1 = require("../utils/forceCustomWrapper");
|
|
22
48
|
const webpack_1 = require("../utils/webpack");
|
|
49
|
+
const SubPackageIndiePlugin_1 = __importStar(require("./SubPackageIndiePlugin"));
|
|
23
50
|
const TaroLoadChunksPlugin_1 = __importDefault(require("./TaroLoadChunksPlugin"));
|
|
24
51
|
const TaroNormalModulesPlugin_1 = __importDefault(require("./TaroNormalModulesPlugin"));
|
|
25
52
|
const TaroSingleEntryPlugin_1 = __importDefault(require("./TaroSingleEntryPlugin"));
|
|
26
|
-
|
|
27
|
-
|
|
53
|
+
exports.baseCompName = 'comp';
|
|
54
|
+
exports.customWrapperName = 'custom-wrapper';
|
|
28
55
|
const PLUGIN_NAME = 'TaroMiniPlugin';
|
|
29
56
|
const CHILD_COMPILER_TAG = 'child';
|
|
57
|
+
exports.STYLE_ISOLATION_APPLY_SHARED = 'apply-shared';
|
|
58
|
+
exports.STYLE_ISOLATION_SHARED = 'shared';
|
|
30
59
|
function isLoaderExist(loaders, loaderName) {
|
|
31
60
|
return loaders.some(item => item.loader === loaderName);
|
|
32
61
|
}
|
|
@@ -46,6 +75,7 @@ class TaroMiniPlugin {
|
|
|
46
75
|
this.dependencies = new Map();
|
|
47
76
|
this.pageLoaderName = '@tarojs/taro-loader/lib/page';
|
|
48
77
|
this.independentPackages = new Map();
|
|
78
|
+
this.subPackageIndiePlugin = null;
|
|
49
79
|
const { combination } = options;
|
|
50
80
|
const miniBuildConfig = combination.config;
|
|
51
81
|
const { template, baseLevel = 16, experimental } = miniBuildConfig;
|
|
@@ -69,6 +99,22 @@ class TaroMiniPlugin {
|
|
|
69
99
|
hot: options.hot,
|
|
70
100
|
loaderMeta: options.loaderMeta || {},
|
|
71
101
|
};
|
|
102
|
+
// 初始化扩展钩子
|
|
103
|
+
this.hooks = {
|
|
104
|
+
modifyEntries: new tapable_1.SyncWaterfallHook(['entries']),
|
|
105
|
+
modifyChunkRequire: new tapable_1.SyncWaterfallHook(['result', 'chunkId', 'miniType']),
|
|
106
|
+
afterResolveModule: new tapable_1.SyncHook(['resolveData']),
|
|
107
|
+
compileExtraEntries: new tapable_1.SyncHook(['compiler', 'compilation', 'promises']),
|
|
108
|
+
modifySkipRootTemplates: new tapable_1.SyncWaterfallHook(['skip']),
|
|
109
|
+
generateExtraFiles: new tapable_1.SyncWaterfallHook(['customWrapperRoots', 'compilation', 'compiler']),
|
|
110
|
+
modifyPageConfig: new tapable_1.SyncWaterfallHook(['context', 'page', 'customWrapperRoots']),
|
|
111
|
+
modifyComponentConfig: new tapable_1.SyncHook(['context', 'customWrapperRoots']),
|
|
112
|
+
afterGenerateFiles: new tapable_1.SyncHook(['compilation', 'compiler']),
|
|
113
|
+
optimizeAssets: new tapable_1.SyncHook(['compilation']),
|
|
114
|
+
modifyConfig: new tapable_1.SyncWaterfallHook(['config', 'componentName']),
|
|
115
|
+
modifyStyleImport: new tapable_1.SyncWaterfallHook(['context', 'page']),
|
|
116
|
+
modifyShouldProcessStyles: new tapable_1.SyncWaterfallHook(['shouldProcess']),
|
|
117
|
+
};
|
|
72
118
|
if (template.isSupportRecursive === false && baseLevel > 0) {
|
|
73
119
|
template.baseLevel = baseLevel;
|
|
74
120
|
}
|
|
@@ -99,11 +145,16 @@ class TaroMiniPlugin {
|
|
|
99
145
|
apply(compiler) {
|
|
100
146
|
this.context = compiler.context;
|
|
101
147
|
this.appEntry = this.getAppEntry(compiler);
|
|
148
|
+
if (this.options.newBlended) {
|
|
149
|
+
this.subPackageIndiePlugin = new SubPackageIndiePlugin_1.default(this);
|
|
150
|
+
this.subPackageIndiePlugin.apply();
|
|
151
|
+
}
|
|
102
152
|
const { commonChunks, combination, framework, isBuildPlugin, newBlended, } = this.options;
|
|
103
153
|
const { addChunkPages, onCompilerMake, modifyBuildAssets, onParseCreateElement, } = combination.config;
|
|
104
154
|
/** build mode */
|
|
105
155
|
compiler.hooks.run.tapAsync(PLUGIN_NAME, this.tryAsync((compiler) => __awaiter(this, void 0, void 0, function* () {
|
|
106
156
|
yield this.run(compiler);
|
|
157
|
+
this.applyForceCustomWrapperDefine(compiler);
|
|
107
158
|
new TaroLoadChunksPlugin_1.default({
|
|
108
159
|
commonChunks: commonChunks,
|
|
109
160
|
isBuildPlugin,
|
|
@@ -119,6 +170,7 @@ class TaroMiniPlugin {
|
|
|
119
170
|
this.isWatch = true;
|
|
120
171
|
}
|
|
121
172
|
yield this.run(compiler);
|
|
173
|
+
this.applyForceCustomWrapperDefine(compiler);
|
|
122
174
|
if (!this.loadChunksPlugin) {
|
|
123
175
|
this.loadChunksPlugin = new TaroLoadChunksPlugin_1.default({
|
|
124
176
|
commonChunks: commonChunks,
|
|
@@ -135,6 +187,7 @@ class TaroMiniPlugin {
|
|
|
135
187
|
const dependencies = this.dependencies;
|
|
136
188
|
const promises = [];
|
|
137
189
|
this.compileIndependentPages(compiler, compilation, dependencies, promises);
|
|
190
|
+
this.hooks.compileExtraEntries.call(compiler, compilation, promises);
|
|
138
191
|
dependencies.forEach(dep => {
|
|
139
192
|
promises.push(new Promise((resolve, reject) => {
|
|
140
193
|
compilation.addEntry(this.options.sourceDir, dep, Object.assign({ name: dep.name }, dep.options), err => err ? reject(err) : resolve(null));
|
|
@@ -147,6 +200,11 @@ class TaroMiniPlugin {
|
|
|
147
200
|
/** For Webpack compilation get factory from compilation.dependencyFactories by denpendence's constructor */
|
|
148
201
|
compilation.dependencyFactories.set(EntryDependency_1.default, normalModuleFactory);
|
|
149
202
|
compilation.dependencyFactories.set(TaroSingleEntryDependency_1.default, normalModuleFactory);
|
|
203
|
+
if (this.options.newBlended) {
|
|
204
|
+
normalModuleFactory.hooks.afterResolve.tap(PLUGIN_NAME, (resolveData) => {
|
|
205
|
+
this.hooks.afterResolveModule.call(resolveData);
|
|
206
|
+
});
|
|
207
|
+
}
|
|
150
208
|
/**
|
|
151
209
|
* webpack NormalModule 在 runLoaders 真正解析资源的前一刻,
|
|
152
210
|
* 往 NormalModule.loaders 中插入对应的 Taro Loader
|
|
@@ -290,6 +348,10 @@ class TaroMiniPlugin {
|
|
|
290
348
|
let source;
|
|
291
349
|
const id = (0, webpack_1.getChunkIdOrName)(chunk);
|
|
292
350
|
const { miniType } = entryModule;
|
|
351
|
+
const modifyResult = this.hooks.modifyChunkRequire.call({ source: modules, handled: false }, id, miniType);
|
|
352
|
+
if (modifyResult === null || modifyResult === void 0 ? void 0 : modifyResult.handled) {
|
|
353
|
+
return modifyResult.source;
|
|
354
|
+
}
|
|
293
355
|
const entryChunk = [{ name: 'app' }];
|
|
294
356
|
// 所有模块都依赖app.js,确保@tarojs\plugin-platform-xxx\dist\runtime.js先于@tarojs/runtime执行,避免Taro API未被初始化
|
|
295
357
|
if (this.nativeComponents.has(id) || miniType === helper_1.META_TYPE.STATIC) {
|
|
@@ -298,7 +360,8 @@ class TaroMiniPlugin {
|
|
|
298
360
|
source = (0, webpack_1.addRequireToSource)(id, modules, v);
|
|
299
361
|
}
|
|
300
362
|
});
|
|
301
|
-
|
|
363
|
+
// 如果没有依赖需要注入,返回原始模块
|
|
364
|
+
return source || modules;
|
|
302
365
|
}
|
|
303
366
|
else if (miniType === helper_1.META_TYPE.PAGE) {
|
|
304
367
|
return (0, webpack_1.addRequireToSource)(id, modules, entryChunk);
|
|
@@ -477,12 +540,12 @@ class TaroMiniPlugin {
|
|
|
477
540
|
}
|
|
478
541
|
if (!this.options.template.isSupportRecursive) {
|
|
479
542
|
pluginJSON.publicComponents = Object.assign({}, publicComponents, {
|
|
480
|
-
[baseCompName]: baseCompName
|
|
543
|
+
[exports.baseCompName]: exports.baseCompName
|
|
481
544
|
});
|
|
482
545
|
}
|
|
483
546
|
if (isUsingCustomWrapper) {
|
|
484
547
|
pluginJSON.publicComponents = Object.assign({}, publicComponents, {
|
|
485
|
-
[customWrapperName]: customWrapperName
|
|
548
|
+
[exports.customWrapperName]: exports.customWrapperName
|
|
486
549
|
});
|
|
487
550
|
}
|
|
488
551
|
}
|
|
@@ -611,8 +674,11 @@ class TaroMiniPlugin {
|
|
|
611
674
|
*/
|
|
612
675
|
addEntry(entryPath, entryName, entryType, options = {}) {
|
|
613
676
|
let dep;
|
|
614
|
-
|
|
615
|
-
|
|
677
|
+
// ★ 对于 STATIC 类型(如 comp/custom-wrapper),使用 entryName 作为 key 的一部分
|
|
678
|
+
// 这允许同一个模板文件被多次添加为不同名称的入口
|
|
679
|
+
const depKey = entryType === helper_1.META_TYPE.STATIC ? `${entryPath}#${entryName}` : entryPath;
|
|
680
|
+
if (this.dependencies.has(depKey)) {
|
|
681
|
+
dep = this.dependencies.get(depKey);
|
|
616
682
|
dep.name = entryName;
|
|
617
683
|
dep.loc = { name: entryName };
|
|
618
684
|
dep.request = entryPath;
|
|
@@ -623,7 +689,7 @@ class TaroMiniPlugin {
|
|
|
623
689
|
else {
|
|
624
690
|
dep = new TaroSingleEntryDependency_1.default(entryPath, entryName, { name: entryName }, entryType, options);
|
|
625
691
|
}
|
|
626
|
-
this.dependencies.set(
|
|
692
|
+
this.dependencies.set(depKey, dep);
|
|
627
693
|
}
|
|
628
694
|
/**
|
|
629
695
|
* 在 this.dependencies 中新增或修改 app、模板组件、页面、组件等资源模块
|
|
@@ -631,10 +697,17 @@ class TaroMiniPlugin {
|
|
|
631
697
|
addEntries() {
|
|
632
698
|
const { template } = this.options;
|
|
633
699
|
this.addEntry(this.appEntry, 'app', helper_1.META_TYPE.ENTRY);
|
|
634
|
-
|
|
700
|
+
const entryFlags = this.hooks.modifyEntries.call({
|
|
701
|
+
skipRootComp: false,
|
|
702
|
+
skipRootWrapper: false,
|
|
703
|
+
});
|
|
704
|
+
if (!template.isSupportRecursive && !entryFlags.skipRootComp) {
|
|
635
705
|
this.addEntry(node_path_1.default.resolve(__dirname, '..', 'template/comp'), 'comp', helper_1.META_TYPE.STATIC);
|
|
636
706
|
}
|
|
637
|
-
|
|
707
|
+
if (!entryFlags.skipRootWrapper) {
|
|
708
|
+
this.addEntry(node_path_1.default.resolve(__dirname, '..', 'template/custom-wrapper'), 'custom-wrapper', helper_1.META_TYPE.STATIC);
|
|
709
|
+
}
|
|
710
|
+
// subPackageIndie 下的 comp/custom-wrapper 统一走独立子编译器,避免被主编译的公共 chunk 共享
|
|
638
711
|
this.pages.forEach(item => {
|
|
639
712
|
if (item.isNative) {
|
|
640
713
|
this.addEntry(item.path, item.name, helper_1.META_TYPE.NORMAL, { isNativePage: true });
|
|
@@ -664,6 +737,34 @@ class TaroMiniPlugin {
|
|
|
664
737
|
}
|
|
665
738
|
});
|
|
666
739
|
}
|
|
740
|
+
computeForceCustomWrapperForWebpackMainComp() {
|
|
741
|
+
var _a;
|
|
742
|
+
if (this.options.template.isSupportRecursive)
|
|
743
|
+
return false;
|
|
744
|
+
const independentPaths = new Set();
|
|
745
|
+
this.independentPackages.forEach(({ pages }) => {
|
|
746
|
+
pages.forEach(p => independentPaths.add(p));
|
|
747
|
+
});
|
|
748
|
+
for (const page of this.pages) {
|
|
749
|
+
if (page.isNative || independentPaths.has(page.path))
|
|
750
|
+
continue;
|
|
751
|
+
const content = (_a = this.filesConfig[this.getConfigFilePath(page.name)]) === null || _a === void 0 ? void 0 : _a.content;
|
|
752
|
+
if (content === null || content === void 0 ? void 0 : content.forceCustomWrapper)
|
|
753
|
+
return true;
|
|
754
|
+
}
|
|
755
|
+
return false;
|
|
756
|
+
}
|
|
757
|
+
computeForceCustomWrapperForIndieRoot(pages) {
|
|
758
|
+
return (0, forceCustomWrapper_1.computeForceCustomWrapperForIndependentPackage)(pages, this.pages, this.filesConfig, (p) => this.getConfigFilePath(p));
|
|
759
|
+
}
|
|
760
|
+
applyForceCustomWrapperDefine(compiler) {
|
|
761
|
+
if (this.options.template.isSupportRecursive)
|
|
762
|
+
return;
|
|
763
|
+
const value = this.computeForceCustomWrapperForWebpackMainComp();
|
|
764
|
+
new compiler.webpack.DefinePlugin({
|
|
765
|
+
TARO_FORCE_CUSTOM_WRAPPER: JSON.stringify(value)
|
|
766
|
+
}).apply(compiler);
|
|
767
|
+
}
|
|
667
768
|
replaceExt(file, ext) {
|
|
668
769
|
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}`);
|
|
669
770
|
}
|
|
@@ -823,7 +924,7 @@ class TaroMiniPlugin {
|
|
|
823
924
|
filename: `[name]${this.options.fileType.style}`,
|
|
824
925
|
chunkFilename: `[name]${this.options.fileType.style}`
|
|
825
926
|
}).apply(childCompiler);
|
|
826
|
-
new compiler.webpack.DefinePlugin(this.options.constantsReplaceList).apply(childCompiler);
|
|
927
|
+
new compiler.webpack.DefinePlugin(Object.assign(Object.assign({}, this.options.constantsReplaceList), { TARO_FORCE_CUSTOM_WRAPPER: JSON.stringify(this.computeForceCustomWrapperForIndieRoot(pages)) })).apply(childCompiler);
|
|
827
928
|
if (compiler.options.optimization) {
|
|
828
929
|
new SplitChunksPlugin({
|
|
829
930
|
chunks: 'all',
|
|
@@ -962,6 +1063,12 @@ class TaroMiniPlugin {
|
|
|
962
1063
|
usingComponents[key] = match ? `${node_path_1.default.sep}${match[0]}` : compPath;
|
|
963
1064
|
}
|
|
964
1065
|
}
|
|
1066
|
+
cloneThirdPartyComponent(thirdPartyComponents, componentName) {
|
|
1067
|
+
const attrs = component_1.componentConfig.thirdPartyComponents.get(componentName);
|
|
1068
|
+
if (!attrs || thirdPartyComponents.has(componentName))
|
|
1069
|
+
return;
|
|
1070
|
+
thirdPartyComponents.set(componentName, new Set(attrs));
|
|
1071
|
+
}
|
|
965
1072
|
/** 生成小程序独立分包的相关文件 */
|
|
966
1073
|
generateIndependentMiniFiles(compilation, compiler) {
|
|
967
1074
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -978,24 +1085,27 @@ class TaroMiniPlugin {
|
|
|
978
1085
|
this.generateTemplateFile(compilation, compiler, `${name}/${baseTemplateName}`, template.buildTemplate, component_1.componentConfig);
|
|
979
1086
|
if (!template.isSupportRecursive) {
|
|
980
1087
|
// 如微信、QQ 不支持递归模版的小程序,需要使用自定义组件协助递归
|
|
981
|
-
|
|
1088
|
+
const compConfig = {
|
|
982
1089
|
component: true,
|
|
983
|
-
styleIsolation:
|
|
1090
|
+
styleIsolation: exports.STYLE_ISOLATION_APPLY_SHARED,
|
|
984
1091
|
usingComponents: {
|
|
985
|
-
[baseCompName]: `./${baseCompName}
|
|
986
|
-
[customWrapperName]: `./${customWrapperName}`
|
|
1092
|
+
[exports.baseCompName]: `./${exports.baseCompName}`
|
|
987
1093
|
}
|
|
988
|
-
}
|
|
989
|
-
|
|
1094
|
+
};
|
|
1095
|
+
if (isUsingCustomWrapper) {
|
|
1096
|
+
compConfig.usingComponents[exports.customWrapperName] = `./${exports.customWrapperName}`;
|
|
1097
|
+
}
|
|
1098
|
+
this.generateConfigFile(compilation, compiler, `${name}/${exports.baseCompName}`, compConfig);
|
|
1099
|
+
this.generateTemplateFile(compilation, compiler, `${name}/${exports.baseCompName}`, template.buildBaseComponentTemplate, this.options.fileType.templ);
|
|
990
1100
|
}
|
|
991
|
-
this.generateConfigFile(compilation, compiler, `${name}/${customWrapperName}`, {
|
|
1101
|
+
this.generateConfigFile(compilation, compiler, `${name}/${exports.customWrapperName}`, {
|
|
992
1102
|
component: true,
|
|
993
|
-
styleIsolation:
|
|
1103
|
+
styleIsolation: exports.STYLE_ISOLATION_APPLY_SHARED,
|
|
994
1104
|
usingComponents: {
|
|
995
|
-
[customWrapperName]: `./${customWrapperName}`
|
|
1105
|
+
[exports.customWrapperName]: `./${exports.customWrapperName}`
|
|
996
1106
|
}
|
|
997
1107
|
});
|
|
998
|
-
this.generateTemplateFile(compilation, compiler, `${name}/${customWrapperName}`, template.buildCustomComponentTemplate, this.options.fileType.templ);
|
|
1108
|
+
this.generateTemplateFile(compilation, compiler, `${name}/${exports.customWrapperName}`, template.buildCustomComponentTemplate, this.options.fileType.templ);
|
|
999
1109
|
this.generateXSFile(compilation, compiler, `${name}/utils`);
|
|
1000
1110
|
});
|
|
1001
1111
|
this.pages.forEach(page => {
|
|
@@ -1018,14 +1128,14 @@ class TaroMiniPlugin {
|
|
|
1018
1128
|
this.generateTemplateFile(compilation, compiler, page.path, template.buildPageTemplate, importBaseTemplatePath, config);
|
|
1019
1129
|
}
|
|
1020
1130
|
if (config) {
|
|
1021
|
-
const importBaseCompPath = (0, helper_1.promoteRelativePath)(node_path_1.default.relative(page.path, node_path_1.default.join(sourceDir, independentName, this.getTargetFilePath(baseCompName, ''))));
|
|
1022
|
-
const importCustomWrapperPath = (0, helper_1.promoteRelativePath)(node_path_1.default.relative(page.path, node_path_1.default.join(sourceDir, independentName, this.getTargetFilePath(customWrapperName, ''))));
|
|
1131
|
+
const importBaseCompPath = (0, helper_1.promoteRelativePath)(node_path_1.default.relative(page.path, node_path_1.default.join(sourceDir, independentName, this.getTargetFilePath(exports.baseCompName, ''))));
|
|
1132
|
+
const importCustomWrapperPath = (0, helper_1.promoteRelativePath)(node_path_1.default.relative(page.path, node_path_1.default.join(sourceDir, independentName, this.getTargetFilePath(exports.customWrapperName, ''))));
|
|
1023
1133
|
config.content.usingComponents = Object.assign({}, config.content.usingComponents);
|
|
1024
1134
|
if (isUsingCustomWrapper) {
|
|
1025
|
-
config.content.usingComponents[customWrapperName] = importCustomWrapperPath;
|
|
1135
|
+
config.content.usingComponents[exports.customWrapperName] = importCustomWrapperPath;
|
|
1026
1136
|
}
|
|
1027
1137
|
if (!template.isSupportRecursive && !page.isNative) {
|
|
1028
|
-
config.content.usingComponents[baseCompName] = importBaseCompPath;
|
|
1138
|
+
config.content.usingComponents[exports.baseCompName] = importBaseCompPath;
|
|
1029
1139
|
}
|
|
1030
1140
|
this.generateConfigFile(compilation, compiler, page.path, config.content);
|
|
1031
1141
|
}
|
|
@@ -1040,6 +1150,8 @@ class TaroMiniPlugin {
|
|
|
1040
1150
|
const { modifyMiniConfigs } = combination.config;
|
|
1041
1151
|
const baseTemplateName = 'base';
|
|
1042
1152
|
const isUsingCustomWrapper = component_1.componentConfig.thirdPartyComponents.has('custom-wrapper');
|
|
1153
|
+
let subPackageIndieCustomWrapperRoots = new Set();
|
|
1154
|
+
compilation[SubPackageIndiePlugin_1.subPackageIndieCustomWrapperRootsKey] = subPackageIndieCustomWrapperRoots;
|
|
1043
1155
|
/**
|
|
1044
1156
|
* 与原生小程序混写时解析模板与样式
|
|
1045
1157
|
*/
|
|
@@ -1059,47 +1171,55 @@ class TaroMiniPlugin {
|
|
|
1059
1171
|
const appConfigName = node_path_1.default.basename(appConfigPath).replace(node_path_1.default.extname(appConfigPath), '');
|
|
1060
1172
|
this.generateConfigFile(compilation, compiler, this.appEntry, this.filesConfig[appConfigName].content);
|
|
1061
1173
|
}
|
|
1062
|
-
|
|
1174
|
+
let skipRootTemplates = false;
|
|
1175
|
+
skipRootTemplates = this.hooks.modifySkipRootTemplates.call(skipRootTemplates);
|
|
1176
|
+
if (!template.isSupportRecursive && !skipRootTemplates) {
|
|
1063
1177
|
// 如微信、QQ 不支持递归模版的小程序,需要使用自定义组件协助递归
|
|
1064
|
-
this.generateTemplateFile(compilation, compiler, baseCompName, template.buildBaseComponentTemplate, this.options.fileType.templ);
|
|
1178
|
+
this.generateTemplateFile(compilation, compiler, exports.baseCompName, template.buildBaseComponentTemplate, this.options.fileType.templ);
|
|
1065
1179
|
const baseCompConfig = {
|
|
1066
1180
|
component: true,
|
|
1067
|
-
styleIsolation:
|
|
1181
|
+
styleIsolation: exports.STYLE_ISOLATION_APPLY_SHARED,
|
|
1068
1182
|
usingComponents: {
|
|
1069
|
-
[baseCompName]: `./${baseCompName}`
|
|
1183
|
+
[exports.baseCompName]: `./${exports.baseCompName}`
|
|
1070
1184
|
}
|
|
1071
1185
|
};
|
|
1072
1186
|
if (isUsingCustomWrapper) {
|
|
1073
|
-
baseCompConfig.usingComponents[customWrapperName] = `./${customWrapperName}`;
|
|
1074
|
-
this.generateConfigFile(compilation, compiler, customWrapperName, {
|
|
1187
|
+
baseCompConfig.usingComponents[exports.customWrapperName] = `./${exports.customWrapperName}`;
|
|
1188
|
+
this.generateConfigFile(compilation, compiler, exports.customWrapperName, {
|
|
1075
1189
|
component: true,
|
|
1076
|
-
styleIsolation:
|
|
1190
|
+
styleIsolation: exports.STYLE_ISOLATION_APPLY_SHARED,
|
|
1077
1191
|
usingComponents: {
|
|
1078
|
-
[baseCompName]: `./${baseCompName}`,
|
|
1079
|
-
[customWrapperName]: `./${customWrapperName}`
|
|
1192
|
+
[exports.baseCompName]: `./${exports.baseCompName}`,
|
|
1193
|
+
[exports.customWrapperName]: `./${exports.customWrapperName}`
|
|
1080
1194
|
}
|
|
1081
1195
|
});
|
|
1082
1196
|
}
|
|
1083
|
-
this.generateConfigFile(compilation, compiler, baseCompName, baseCompConfig);
|
|
1197
|
+
this.generateConfigFile(compilation, compiler, exports.baseCompName, baseCompConfig);
|
|
1084
1198
|
}
|
|
1085
|
-
else {
|
|
1199
|
+
else if (!skipRootTemplates) {
|
|
1086
1200
|
if (isUsingCustomWrapper) {
|
|
1087
|
-
this.generateConfigFile(compilation, compiler, customWrapperName, {
|
|
1201
|
+
this.generateConfigFile(compilation, compiler, exports.customWrapperName, {
|
|
1088
1202
|
component: true,
|
|
1089
|
-
styleIsolation:
|
|
1203
|
+
styleIsolation: exports.STYLE_ISOLATION_APPLY_SHARED,
|
|
1090
1204
|
usingComponents: {
|
|
1091
|
-
[customWrapperName]: `./${customWrapperName}`
|
|
1205
|
+
[exports.customWrapperName]: `./${exports.customWrapperName}`
|
|
1092
1206
|
}
|
|
1093
1207
|
});
|
|
1094
1208
|
}
|
|
1095
1209
|
}
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1210
|
+
// ★ 当配置了 mainPackageRoot 时,跳过根目录 base.wxml 和 utils.wxs 的生成
|
|
1211
|
+
if (!skipRootTemplates) {
|
|
1212
|
+
this.generateTemplateFile(compilation, compiler, baseTemplateName, template.buildTemplate, component_1.componentConfig);
|
|
1213
|
+
isUsingCustomWrapper && this.generateTemplateFile(compilation, compiler, exports.customWrapperName, template.buildCustomComponentTemplate, this.options.fileType.templ);
|
|
1214
|
+
this.generateXSFile(compilation, compiler, 'utils');
|
|
1215
|
+
}
|
|
1216
|
+
subPackageIndieCustomWrapperRoots = this.hooks.generateExtraFiles.call(subPackageIndieCustomWrapperRoots, compilation, compiler);
|
|
1217
|
+
compilation[SubPackageIndiePlugin_1.subPackageIndieCustomWrapperRootsKey] = subPackageIndieCustomWrapperRoots;
|
|
1099
1218
|
this.components.forEach(component => {
|
|
1100
1219
|
const importBaseTemplatePath = (0, helper_1.promoteRelativePath)(node_path_1.default.relative(component.path, node_path_1.default.join(sourceDir, isBuildPlugin ? 'plugin' : '', this.getTemplatePath(baseTemplateName))));
|
|
1101
1220
|
const config = this.filesConfig[this.getConfigFilePath(component.name)];
|
|
1102
1221
|
if (config) {
|
|
1222
|
+
this.hooks.modifyComponentConfig.call({ config, component }, subPackageIndieCustomWrapperRoots);
|
|
1103
1223
|
this.generateConfigFile(compilation, compiler, component.path, config.content);
|
|
1104
1224
|
}
|
|
1105
1225
|
if (!component.isNative) {
|
|
@@ -1107,31 +1227,46 @@ class TaroMiniPlugin {
|
|
|
1107
1227
|
}
|
|
1108
1228
|
});
|
|
1109
1229
|
this.pages.forEach(page => {
|
|
1110
|
-
|
|
1230
|
+
let importBaseTemplatePath = (0, helper_1.promoteRelativePath)(node_path_1.default.relative(page.path, node_path_1.default.join(sourceDir, isBuildPlugin ? 'plugin' : '', this.getTemplatePath(baseTemplateName))));
|
|
1111
1231
|
const config = this.filesConfig[this.getConfigFilePath(page.name)];
|
|
1112
1232
|
// pages 里面会混合独立分包的,在这里需要过滤一下,避免重复生成 assets
|
|
1113
1233
|
const isIndependent = !!this.getIndependentPackage(page.path);
|
|
1114
1234
|
if (isIndependent)
|
|
1115
1235
|
return;
|
|
1116
1236
|
// 生成页面模板需要在生成页面配置之前,因为会依赖到页面配置的部分内容
|
|
1237
|
+
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, ''))));
|
|
1238
|
+
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, ''))));
|
|
1239
|
+
let isPageRecursiveDisabled = false;
|
|
1240
|
+
let shouldUseCustomWrapper = isUsingCustomWrapper;
|
|
1241
|
+
const pageConfigContext = this.hooks.modifyPageConfig.call({
|
|
1242
|
+
importBaseTemplatePath,
|
|
1243
|
+
importBaseCompPath,
|
|
1244
|
+
importCustomWrapperPath,
|
|
1245
|
+
shouldUseCustomWrapper,
|
|
1246
|
+
isPageRecursiveDisabled,
|
|
1247
|
+
}, page, subPackageIndieCustomWrapperRoots);
|
|
1248
|
+
importBaseTemplatePath = pageConfigContext.importBaseTemplatePath;
|
|
1249
|
+
importBaseCompPath = pageConfigContext.importBaseCompPath;
|
|
1250
|
+
importCustomWrapperPath = pageConfigContext.importCustomWrapperPath;
|
|
1251
|
+
shouldUseCustomWrapper = pageConfigContext.shouldUseCustomWrapper;
|
|
1252
|
+
isPageRecursiveDisabled = pageConfigContext.isPageRecursiveDisabled;
|
|
1117
1253
|
if (!page.isNative) {
|
|
1118
1254
|
this.generateTemplateFile(compilation, compiler, page.path, template.buildPageTemplate, importBaseTemplatePath, config);
|
|
1119
1255
|
}
|
|
1120
1256
|
if (config) {
|
|
1121
|
-
const importBaseCompPath = (0, helper_1.promoteRelativePath)(node_path_1.default.relative(page.path, node_path_1.default.join(sourceDir, isBuildPlugin ? 'plugin' : '', this.getTargetFilePath(baseCompName, ''))));
|
|
1122
|
-
const importCustomWrapperPath = (0, helper_1.promoteRelativePath)(node_path_1.default.relative(page.path, node_path_1.default.join(sourceDir, isBuildPlugin ? 'plugin' : '', this.getTargetFilePath(customWrapperName, ''))));
|
|
1123
1257
|
config.content.usingComponents = Object.assign({}, config.content.usingComponents);
|
|
1124
|
-
if (
|
|
1125
|
-
config.content.usingComponents[customWrapperName] = importCustomWrapperPath;
|
|
1258
|
+
if (shouldUseCustomWrapper) {
|
|
1259
|
+
config.content.usingComponents[exports.customWrapperName] = importCustomWrapperPath;
|
|
1126
1260
|
}
|
|
1127
|
-
if (!template.isSupportRecursive && !page.isNative) {
|
|
1128
|
-
config.content.usingComponents[baseCompName] = importBaseCompPath;
|
|
1261
|
+
if (!template.isSupportRecursive && !page.isNative && !isPageRecursiveDisabled) {
|
|
1262
|
+
config.content.usingComponents[exports.baseCompName] = importBaseCompPath;
|
|
1129
1263
|
}
|
|
1130
1264
|
this.generateConfigFile(compilation, compiler, page.path, config.content);
|
|
1131
1265
|
}
|
|
1132
1266
|
});
|
|
1133
1267
|
this.generateTabBarFiles(compilation, compiler);
|
|
1134
1268
|
this.injectCommonStyles(compilation, compiler);
|
|
1269
|
+
this.hooks.afterGenerateFiles.call(compilation, compiler);
|
|
1135
1270
|
if (this.themeLocation) {
|
|
1136
1271
|
this.generateDarkModeFile(compilation, compiler);
|
|
1137
1272
|
}
|
|
@@ -1164,12 +1299,15 @@ class TaroMiniPlugin {
|
|
|
1164
1299
|
delete compilation.assets[assetPath];
|
|
1165
1300
|
}
|
|
1166
1301
|
});
|
|
1302
|
+
this.hooks.optimizeAssets.call(compilation);
|
|
1167
1303
|
});
|
|
1168
1304
|
}
|
|
1169
1305
|
generateConfigFile(compilation, compiler, filePath, config) {
|
|
1170
1306
|
const { RawSource } = compiler.webpack.sources;
|
|
1171
1307
|
const fileConfigName = this.getConfigPath(this.getComponentName(filePath));
|
|
1172
|
-
const
|
|
1308
|
+
const componentName = this.getComponentName(filePath);
|
|
1309
|
+
config = this.hooks.modifyConfig.call(config, componentName);
|
|
1310
|
+
const unofficialConfigs = ['enableShareAppMessage', 'enableShareTimeline', 'enablePageMeta', 'components', 'forceCustomWrapper'];
|
|
1173
1311
|
unofficialConfigs.forEach(item => {
|
|
1174
1312
|
delete config[item];
|
|
1175
1313
|
});
|
|
@@ -1315,12 +1453,21 @@ class TaroMiniPlugin {
|
|
|
1315
1453
|
});
|
|
1316
1454
|
});
|
|
1317
1455
|
}
|
|
1318
|
-
|
|
1456
|
+
// 判断是否需要处理样式:有 common chunks 或者有 app.wxss(可被扩展插件修改)
|
|
1457
|
+
const hasAppStyle = !!assets[appStyle];
|
|
1458
|
+
let shouldProcessStyles = commons.size() > 0;
|
|
1459
|
+
if (!hasAppStyle) {
|
|
1460
|
+
shouldProcessStyles = false;
|
|
1461
|
+
}
|
|
1462
|
+
shouldProcessStyles = this.hooks.modifyShouldProcessStyles.call(shouldProcessStyles);
|
|
1463
|
+
if (shouldProcessStyles) {
|
|
1319
1464
|
const APP_STYLE_NAME = 'app-origin' + styleExt;
|
|
1320
1465
|
assets[APP_STYLE_NAME] = new ConcatSource(originSource);
|
|
1321
1466
|
const source = new ConcatSource('');
|
|
1322
1467
|
source.add(`@import ${JSON.stringify((0, loader_utils_1.urlToRequest)(APP_STYLE_NAME))};`);
|
|
1323
|
-
|
|
1468
|
+
if (commons.size() > 0) {
|
|
1469
|
+
source.add(commons);
|
|
1470
|
+
}
|
|
1324
1471
|
source.add('\n');
|
|
1325
1472
|
assets[appStyle] = source;
|
|
1326
1473
|
if (newBlended) {
|
|
@@ -1336,14 +1483,43 @@ class TaroMiniPlugin {
|
|
|
1336
1483
|
}
|
|
1337
1484
|
const source = new ConcatSource('');
|
|
1338
1485
|
const originSource = assets[pageStyle];
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1486
|
+
const styleImportContext = this.hooks.modifyStyleImport.call({
|
|
1487
|
+
importStatement: '',
|
|
1488
|
+
shouldSkip: false,
|
|
1489
|
+
isMainPackageRoot: false,
|
|
1490
|
+
}, page);
|
|
1491
|
+
if (styleImportContext.shouldSkip) {
|
|
1492
|
+
// no-op
|
|
1493
|
+
}
|
|
1494
|
+
else if (styleImportContext.importStatement) {
|
|
1495
|
+
source.add(styleImportContext.importStatement);
|
|
1496
|
+
}
|
|
1497
|
+
else {
|
|
1498
|
+
componentCommons.forEach(item => {
|
|
1499
|
+
source.add(`@import ${JSON.stringify((0, loader_utils_1.urlToRequest)(node_path_1.default.posix.relative(node_path_1.default.dirname(pageStyle), item)))};\n`);
|
|
1500
|
+
});
|
|
1501
|
+
}
|
|
1342
1502
|
source.add(originSource);
|
|
1343
1503
|
assets[pageStyle] = source;
|
|
1344
1504
|
}
|
|
1345
1505
|
else {
|
|
1346
|
-
|
|
1506
|
+
// 普通页面(非本地化组件)
|
|
1507
|
+
const styleImportContext = this.hooks.modifyStyleImport.call({
|
|
1508
|
+
importStatement: '',
|
|
1509
|
+
shouldSkip: false,
|
|
1510
|
+
isMainPackageRoot: false,
|
|
1511
|
+
}, page);
|
|
1512
|
+
if (styleImportContext.importStatement) {
|
|
1513
|
+
const source = new ConcatSource('');
|
|
1514
|
+
if (pageStyle in assets) {
|
|
1515
|
+
source.add(assets[pageStyle]);
|
|
1516
|
+
}
|
|
1517
|
+
const importSource = new ConcatSource('');
|
|
1518
|
+
importSource.add(styleImportContext.importStatement);
|
|
1519
|
+
importSource.add(source);
|
|
1520
|
+
assets[pageStyle] = importSource;
|
|
1521
|
+
}
|
|
1522
|
+
else if (pageStyle in assets) {
|
|
1347
1523
|
const source = new ConcatSource('');
|
|
1348
1524
|
const originSource = assets[pageStyle];
|
|
1349
1525
|
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`);
|