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