@tarojs/webpack5-runner 3.7.0-canary.0 → 3.8.0-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.h5.js +4 -1
- package/dist/index.h5.js.map +1 -1
- package/dist/loaders/miniCompilerLoader.js +112 -0
- package/dist/loaders/miniCompilerLoader.js.map +1 -0
- package/dist/loaders/miniXScriptLoader.js.map +1 -1
- package/dist/plugins/H5Plugin.js +1 -6
- package/dist/plugins/H5Plugin.js.map +1 -1
- package/dist/plugins/MiniPlugin.js +322 -64
- package/dist/plugins/MiniPlugin.js.map +1 -1
- package/dist/plugins/MiniSplitChunksPlugin.js +96 -90
- package/dist/plugins/MiniSplitChunksPlugin.js.map +1 -1
- package/dist/plugins/TaroComponentsExportsPlugin.js +28 -11
- package/dist/plugins/TaroComponentsExportsPlugin.js.map +1 -1
- package/dist/plugins/TaroLoadChunksPlugin.js +2 -2
- package/dist/plugins/TaroLoadChunksPlugin.js.map +1 -1
- package/dist/plugins/TaroNormalModule.js +79 -1
- package/dist/plugins/TaroNormalModule.js.map +1 -1
- package/dist/plugins/TaroNormalModulesPlugin.js +69 -31
- package/dist/plugins/TaroNormalModulesPlugin.js.map +1 -1
- package/dist/plugins/TaroSingleEntryPlugin.js +6 -5
- package/dist/plugins/TaroSingleEntryPlugin.js.map +1 -1
- package/dist/utils/component.js +4 -1
- package/dist/utils/component.js.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/webpack/Combination.js +10 -7
- package/dist/webpack/Combination.js.map +1 -1
- package/dist/webpack/H5BaseConfig.js +7 -16
- package/dist/webpack/H5BaseConfig.js.map +1 -1
- package/dist/webpack/H5Combination.js +0 -1
- package/dist/webpack/H5Combination.js.map +1 -1
- package/dist/webpack/MiniBaseConfig.js +12 -18
- package/dist/webpack/MiniBaseConfig.js.map +1 -1
- package/dist/webpack/MiniCombination.js +0 -1
- package/dist/webpack/MiniCombination.js.map +1 -1
- package/dist/webpack/MiniWebpackModule.js +7 -2
- package/dist/webpack/MiniWebpackModule.js.map +1 -1
- package/dist/webpack/MiniWebpackPlugin.js +3 -1
- package/dist/webpack/MiniWebpackPlugin.js.map +1 -1
- package/dist/webpack/WebpackModule.js +3 -0
- package/dist/webpack/WebpackModule.js.map +1 -1
- package/package.json +19 -20
|
@@ -19,10 +19,14 @@ const EntryDependency_1 = __importDefault(require("webpack/lib/dependencies/Entr
|
|
|
19
19
|
const TaroSingleEntryDependency_1 = __importDefault(require("../dependencies/TaroSingleEntryDependency"));
|
|
20
20
|
const prerender_1 = require("../prerender/prerender");
|
|
21
21
|
const component_1 = require("../utils/component");
|
|
22
|
+
const webpack_1 = require("../utils/webpack");
|
|
22
23
|
const TaroLoadChunksPlugin_1 = __importDefault(require("./TaroLoadChunksPlugin"));
|
|
23
24
|
const TaroNormalModulesPlugin_1 = __importDefault(require("./TaroNormalModulesPlugin"));
|
|
24
25
|
const TaroSingleEntryPlugin_1 = __importDefault(require("./TaroSingleEntryPlugin"));
|
|
26
|
+
const baseCompName = 'comp';
|
|
27
|
+
const customWrapperName = 'custom-wrapper';
|
|
25
28
|
const PLUGIN_NAME = 'TaroMiniPlugin';
|
|
29
|
+
const CHILD_COMPILER_TAG = 'child';
|
|
26
30
|
function isLoaderExist(loaders, loaderName) {
|
|
27
31
|
return loaders.some(item => item.loader === loaderName);
|
|
28
32
|
}
|
|
@@ -34,6 +38,8 @@ class TaroMiniPlugin {
|
|
|
34
38
|
/** 页面列表 */
|
|
35
39
|
this.pages = new Set();
|
|
36
40
|
this.components = new Set();
|
|
41
|
+
/** 新的混合原生编译模式 newBlended 模式下,需要单独编译成原生代码的 component 的Map */
|
|
42
|
+
this.nativeComponents = new Map();
|
|
37
43
|
/** tabbar icon 图片路径列表 */
|
|
38
44
|
this.tabBarIcons = new Set();
|
|
39
45
|
this.dependencies = new Map();
|
|
@@ -80,7 +86,7 @@ class TaroMiniPlugin {
|
|
|
80
86
|
apply(compiler) {
|
|
81
87
|
this.context = compiler.context;
|
|
82
88
|
this.appEntry = this.getAppEntry(compiler);
|
|
83
|
-
const { commonChunks, addChunkPages, framework, isBuildPlugin } = this.options;
|
|
89
|
+
const { commonChunks, addChunkPages, framework, isBuildPlugin, newBlended, } = this.options;
|
|
84
90
|
/** build mode */
|
|
85
91
|
compiler.hooks.run.tapAsync(PLUGIN_NAME, this.tryAsync((compiler) => __awaiter(this, void 0, void 0, function* () {
|
|
86
92
|
yield this.run(compiler);
|
|
@@ -146,6 +152,7 @@ class TaroMiniPlugin {
|
|
|
146
152
|
config: this.appConfig,
|
|
147
153
|
runtimePath: this.options.runtimePath,
|
|
148
154
|
blended: this.options.blended,
|
|
155
|
+
newBlended: this.options.newBlended,
|
|
149
156
|
pxTransformConfig
|
|
150
157
|
}
|
|
151
158
|
});
|
|
@@ -158,13 +165,19 @@ class TaroMiniPlugin {
|
|
|
158
165
|
isIndependent = true;
|
|
159
166
|
}
|
|
160
167
|
});
|
|
161
|
-
const
|
|
168
|
+
const isNewBlended = this.nativeComponents.has(module.name);
|
|
169
|
+
const loaderName = (isNewBlended || isBuildPlugin)
|
|
170
|
+
? '@tarojs/taro-loader/lib/native-component'
|
|
171
|
+
: (isIndependent
|
|
172
|
+
? '@tarojs/taro-loader/lib/independentPage'
|
|
173
|
+
: this.pageLoaderName);
|
|
162
174
|
if (!isLoaderExist(module.loaders, loaderName)) {
|
|
163
175
|
module.loaders.unshift({
|
|
164
176
|
loader: loaderName,
|
|
165
177
|
options: {
|
|
166
178
|
framework,
|
|
167
179
|
loaderMeta,
|
|
180
|
+
isNewBlended,
|
|
168
181
|
name: module.name,
|
|
169
182
|
prerender: this.prerenderPages.has(module.name),
|
|
170
183
|
config: this.filesConfig,
|
|
@@ -191,18 +204,93 @@ class TaroMiniPlugin {
|
|
|
191
204
|
}
|
|
192
205
|
}
|
|
193
206
|
});
|
|
194
|
-
const { PROCESS_ASSETS_STAGE_ADDITIONAL } = compiler.webpack.Compilation;
|
|
207
|
+
const { PROCESS_ASSETS_STAGE_ADDITIONAL, PROCESS_ASSETS_STAGE_OPTIMIZE, PROCESS_ASSETS_STAGE_REPORT } = compiler.webpack.Compilation;
|
|
195
208
|
compilation.hooks.processAssets.tapAsync({
|
|
196
209
|
name: PLUGIN_NAME,
|
|
197
210
|
stage: PROCESS_ASSETS_STAGE_ADDITIONAL
|
|
198
211
|
}, this.tryAsync(() => __awaiter(this, void 0, void 0, function* () {
|
|
199
|
-
|
|
212
|
+
// 如果是子编译器,证明是编译独立分包,进行单独的处理
|
|
213
|
+
if (compilation.__tag === CHILD_COMPILER_TAG) {
|
|
214
|
+
yield this.generateIndependentMiniFiles(compilation, compiler);
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
yield this.generateMiniFiles(compilation, compiler);
|
|
218
|
+
}
|
|
219
|
+
})));
|
|
220
|
+
compilation.hooks.processAssets.tapAsync({
|
|
221
|
+
name: PLUGIN_NAME,
|
|
222
|
+
// 删除 assets 的相关操作放在触发时机较后的 Stage,避免过早删除出现的一些问题,#13988
|
|
223
|
+
// Stage 触发顺序:https://webpack.js.org/api/compilation-hooks/#list-of-asset-processing-stages
|
|
224
|
+
stage: PROCESS_ASSETS_STAGE_OPTIMIZE
|
|
225
|
+
}, this.tryAsync(() => __awaiter(this, void 0, void 0, function* () {
|
|
226
|
+
yield this.optimizeMiniFiles(compilation, compiler);
|
|
227
|
+
})));
|
|
228
|
+
compilation.hooks.processAssets.tapAsync({
|
|
229
|
+
name: PLUGIN_NAME,
|
|
230
|
+
// 该 stage 是最后执行的,确保 taro 暴露给用户的钩子 modifyBuildAssets 在内部处理完 assets 之后再调用
|
|
231
|
+
stage: PROCESS_ASSETS_STAGE_REPORT
|
|
232
|
+
}, this.tryAsync(() => __awaiter(this, void 0, void 0, function* () {
|
|
233
|
+
const { modifyBuildAssets } = this.options;
|
|
234
|
+
if (typeof modifyBuildAssets === 'function') {
|
|
235
|
+
yield modifyBuildAssets(compilation.assets, this);
|
|
236
|
+
}
|
|
200
237
|
})));
|
|
201
238
|
});
|
|
202
239
|
compiler.hooks.afterEmit.tapAsync(PLUGIN_NAME, this.tryAsync((compilation) => __awaiter(this, void 0, void 0, function* () {
|
|
203
240
|
yield this.addTarBarFilesToDependencies(compilation);
|
|
204
241
|
})));
|
|
205
242
|
new TaroNormalModulesPlugin_1.default(this.options.onParseCreateElement).apply(compiler);
|
|
243
|
+
newBlended && this.addLoadChunksPlugin(compiler);
|
|
244
|
+
}
|
|
245
|
+
addLoadChunksPlugin(compiler) {
|
|
246
|
+
const fileChunks = new Map();
|
|
247
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
|
|
248
|
+
compilation.hooks.afterOptimizeChunks.tap(PLUGIN_NAME, chunks => {
|
|
249
|
+
for (const chunk of chunks) {
|
|
250
|
+
const id = (0, webpack_1.getChunkIdOrName)(chunk);
|
|
251
|
+
if (this.options.commonChunks.includes(id))
|
|
252
|
+
return;
|
|
253
|
+
const deps = [];
|
|
254
|
+
for (const group of chunk.groupsIterable) {
|
|
255
|
+
group.chunks.forEach(chunk => {
|
|
256
|
+
const currentChunkId = (0, webpack_1.getChunkIdOrName)(chunk);
|
|
257
|
+
if (id === currentChunkId)
|
|
258
|
+
return;
|
|
259
|
+
deps.push({
|
|
260
|
+
name: currentChunkId
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
fileChunks.set(id, deps);
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
compiler.webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(compilation).render.tap(PLUGIN_NAME, (modules, { chunk }) => {
|
|
268
|
+
var _a;
|
|
269
|
+
const chunkEntryModule = (0, webpack_1.getChunkEntryModule)(compilation, chunk);
|
|
270
|
+
if (!chunkEntryModule)
|
|
271
|
+
return;
|
|
272
|
+
const entryModule = (_a = chunkEntryModule.rootModule) !== null && _a !== void 0 ? _a : chunkEntryModule;
|
|
273
|
+
// addChunkPages
|
|
274
|
+
if (fileChunks.size) {
|
|
275
|
+
let source;
|
|
276
|
+
const id = (0, webpack_1.getChunkIdOrName)(chunk);
|
|
277
|
+
const { miniType } = entryModule;
|
|
278
|
+
const entryChunk = [{ name: 'app' }];
|
|
279
|
+
// 所有模块都依赖app.js,确保@tarojs\plugin-platform-xxx\dist\runtime.js先于@tarojs/runtime执行,避免Taro API未被初始化
|
|
280
|
+
if (this.nativeComponents.has(id) || miniType === helper_1.META_TYPE.STATIC) {
|
|
281
|
+
fileChunks.forEach((v, k) => {
|
|
282
|
+
if (k === id) {
|
|
283
|
+
source = (0, webpack_1.addRequireToSource)(id, modules, v);
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
return source;
|
|
287
|
+
}
|
|
288
|
+
else if (miniType === helper_1.META_TYPE.PAGE) {
|
|
289
|
+
return (0, webpack_1.addRequireToSource)(id, modules, entryChunk);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
});
|
|
206
294
|
}
|
|
207
295
|
/**
|
|
208
296
|
* 根据 webpack entry 配置获取入口文件路径
|
|
@@ -331,7 +419,7 @@ class TaroMiniPlugin {
|
|
|
331
419
|
}
|
|
332
420
|
this.compileFile(item);
|
|
333
421
|
if (item.isNative) {
|
|
334
|
-
this.addEntry(item.path, item.name, helper_1.META_TYPE.NORMAL);
|
|
422
|
+
this.addEntry(item.path, item.name, helper_1.META_TYPE.NORMAL, { isNativePage: true });
|
|
335
423
|
if (item.stylePath && helper_1.fs.existsSync(item.stylePath)) {
|
|
336
424
|
this.addEntry(item.stylePath, this.getStylePath(item.name), helper_1.META_TYPE.NORMAL);
|
|
337
425
|
}
|
|
@@ -346,7 +434,7 @@ class TaroMiniPlugin {
|
|
|
346
434
|
this.components.forEach(item => {
|
|
347
435
|
this.compileFile(item);
|
|
348
436
|
if (item.isNative) {
|
|
349
|
-
this.addEntry(item.path, item.name, helper_1.META_TYPE.NORMAL);
|
|
437
|
+
this.addEntry(item.path, item.name, helper_1.META_TYPE.NORMAL, { isNativePage: true });
|
|
350
438
|
if (item.stylePath && helper_1.fs.existsSync(item.stylePath)) {
|
|
351
439
|
this.addEntry(item.stylePath, this.getStylePath(item.name), helper_1.META_TYPE.NORMAL);
|
|
352
440
|
}
|
|
@@ -365,9 +453,14 @@ class TaroMiniPlugin {
|
|
|
365
453
|
if (main) {
|
|
366
454
|
pluginJSON.main = this.getTargetFilePath(main, '.js');
|
|
367
455
|
}
|
|
368
|
-
if (
|
|
456
|
+
if (!this.options.template.isSupportRecursive) {
|
|
369
457
|
pluginJSON.publicComponents = Object.assign({}, publicComponents, {
|
|
370
|
-
|
|
458
|
+
[baseCompName]: baseCompName
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
if (isUsingCustomWrapper) {
|
|
462
|
+
pluginJSON.publicComponents = Object.assign({}, publicComponents, {
|
|
463
|
+
[customWrapperName]: customWrapperName
|
|
371
464
|
});
|
|
372
465
|
}
|
|
373
466
|
}
|
|
@@ -395,6 +488,7 @@ class TaroMiniPlugin {
|
|
|
395
488
|
*/
|
|
396
489
|
getPages() {
|
|
397
490
|
var _a;
|
|
491
|
+
const { newBlended } = this.options;
|
|
398
492
|
if ((0, helper_1.isEmptyObject)(this.appConfig)) {
|
|
399
493
|
throw new Error('缺少 app 全局配置文件,请检查!');
|
|
400
494
|
}
|
|
@@ -423,6 +517,30 @@ class TaroMiniPlugin {
|
|
|
423
517
|
})
|
|
424
518
|
]);
|
|
425
519
|
this.getSubPackages(this.appConfig);
|
|
520
|
+
// 新的混合原生编译模式 newBlended 下,需要收集独立编译为原生自定义组件
|
|
521
|
+
newBlended && this.getNativeComponent();
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* 收集需要转换为本地化组件的内容
|
|
525
|
+
*/
|
|
526
|
+
getNativeComponent() {
|
|
527
|
+
const { frameworkExts } = this.options;
|
|
528
|
+
const components = this.appConfig.components || [];
|
|
529
|
+
components.forEach(item => {
|
|
530
|
+
var _a;
|
|
531
|
+
const pagePath = (0, helper_1.resolveMainFilePath)(path_1.default.join(this.options.sourceDir, item), frameworkExts);
|
|
532
|
+
const componentObj = {
|
|
533
|
+
name: item,
|
|
534
|
+
path: pagePath,
|
|
535
|
+
isNative: false,
|
|
536
|
+
};
|
|
537
|
+
if (!this.isWatch && ((_a = this.options.logger) === null || _a === void 0 ? void 0 : _a.quiet) === false) {
|
|
538
|
+
(0, helper_1.printLog)("compile" /* processTypeEnum.COMPILE */, `发现[${item}]Native组件`);
|
|
539
|
+
}
|
|
540
|
+
this.pages.add(componentObj);
|
|
541
|
+
// 登记需要编译成原生版本的组件
|
|
542
|
+
this.nativeComponents.set(item, componentObj);
|
|
543
|
+
});
|
|
426
544
|
}
|
|
427
545
|
/**
|
|
428
546
|
* 读取页面及其依赖的组件的配置
|
|
@@ -489,7 +607,7 @@ class TaroMiniPlugin {
|
|
|
489
607
|
this.addEntry(path_1.default.resolve(__dirname, '..', 'template/custom-wrapper'), 'custom-wrapper', helper_1.META_TYPE.STATIC);
|
|
490
608
|
this.pages.forEach(item => {
|
|
491
609
|
if (item.isNative) {
|
|
492
|
-
this.addEntry(item.path, item.name, helper_1.META_TYPE.NORMAL);
|
|
610
|
+
this.addEntry(item.path, item.name, helper_1.META_TYPE.NORMAL, { isNativePage: true });
|
|
493
611
|
if (item.stylePath && helper_1.fs.existsSync(item.stylePath)) {
|
|
494
612
|
this.addEntry(item.stylePath, this.getStylePath(item.name), helper_1.META_TYPE.NORMAL);
|
|
495
613
|
}
|
|
@@ -503,7 +621,7 @@ class TaroMiniPlugin {
|
|
|
503
621
|
});
|
|
504
622
|
this.components.forEach(item => {
|
|
505
623
|
if (item.isNative) {
|
|
506
|
-
this.addEntry(item.path, item.name, helper_1.META_TYPE.NORMAL);
|
|
624
|
+
this.addEntry(item.path, item.name, helper_1.META_TYPE.NORMAL, { isNativePage: true });
|
|
507
625
|
if (item.stylePath && helper_1.fs.existsSync(item.stylePath)) {
|
|
508
626
|
this.addEntry(item.stylePath, this.getStylePath(item.name), helper_1.META_TYPE.NORMAL);
|
|
509
627
|
}
|
|
@@ -526,7 +644,17 @@ class TaroMiniPlugin {
|
|
|
526
644
|
const filePath = file.path;
|
|
527
645
|
const fileConfigPath = file.isNative ? this.replaceExt(filePath, '.json') : this.getConfigFilePath(filePath);
|
|
528
646
|
const fileConfig = (0, helper_1.readConfig)(fileConfigPath);
|
|
647
|
+
const { componentGenerics } = fileConfig;
|
|
529
648
|
const usingComponents = fileConfig.usingComponents;
|
|
649
|
+
if (this.options.isBuildPlugin && componentGenerics) {
|
|
650
|
+
Object.keys(componentGenerics).forEach(component => {
|
|
651
|
+
if (componentGenerics[component]) {
|
|
652
|
+
if (!component_1.componentConfig.thirdPartyComponents.has(component)) {
|
|
653
|
+
component_1.componentConfig.thirdPartyComponents.set(component, new Set());
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
}
|
|
530
658
|
// 递归收集依赖的第三方组件
|
|
531
659
|
if (usingComponents) {
|
|
532
660
|
const componentNames = Object.keys(usingComponents);
|
|
@@ -538,6 +666,17 @@ class TaroMiniPlugin {
|
|
|
538
666
|
compPath = (0, helper_1.replaceAliasPath)(filePath, compPath, alias);
|
|
539
667
|
fileConfig.usingComponents[compName] = compPath;
|
|
540
668
|
}
|
|
669
|
+
// 判断是否为第三方依赖的正则,如果 test 为 false 则为第三方依赖
|
|
670
|
+
const notNpmPkgReg = /^[.\\/]/;
|
|
671
|
+
if (!this.options.skipProcessUsingComponents
|
|
672
|
+
&& !compPath.startsWith('plugin://')
|
|
673
|
+
&& !notNpmPkgReg.test(compPath)) {
|
|
674
|
+
const tempCompPath = (0, helper_1.getNpmPackageAbsolutePath)(compPath);
|
|
675
|
+
if (tempCompPath) {
|
|
676
|
+
compPath = tempCompPath;
|
|
677
|
+
fileConfig.usingComponents[compName] = compPath;
|
|
678
|
+
}
|
|
679
|
+
}
|
|
541
680
|
depComponents.push({
|
|
542
681
|
name: compName,
|
|
543
682
|
path: compPath
|
|
@@ -550,6 +689,9 @@ class TaroMiniPlugin {
|
|
|
550
689
|
const componentPath = (0, helper_1.resolveMainFilePath)(path_1.default.resolve(path_1.default.dirname(file.path), item.path));
|
|
551
690
|
if (helper_1.fs.existsSync(componentPath) && !Array.from(this.components).some(item => item.path === componentPath)) {
|
|
552
691
|
const componentName = this.getComponentName(componentPath);
|
|
692
|
+
// newBlended 模式下,本地化组件使用Page进行处理,此处直接跳过
|
|
693
|
+
if (this.nativeComponents.has(componentName))
|
|
694
|
+
return;
|
|
553
695
|
const componentTempPath = this.getTemplatePath(componentPath);
|
|
554
696
|
const isNative = this.isNativePageORComponent(componentTempPath);
|
|
555
697
|
const componentObj = {
|
|
@@ -676,7 +818,7 @@ class TaroMiniPlugin {
|
|
|
676
818
|
pages.forEach(pagePath => {
|
|
677
819
|
if (dependencies.has(pagePath)) {
|
|
678
820
|
const dep = dependencies.get(pagePath);
|
|
679
|
-
new TaroSingleEntryPlugin_1.default(compiler.context, dep === null || dep === void 0 ? void 0 : dep.request, dep === null || dep === void 0 ? void 0 : dep.name, dep === null || dep === void 0 ? void 0 : dep.miniType).apply(childCompiler);
|
|
821
|
+
new TaroSingleEntryPlugin_1.default(compiler.context, dep === null || dep === void 0 ? void 0 : dep.request, dep === null || dep === void 0 ? void 0 : dep.name, dep === null || dep === void 0 ? void 0 : dep.miniType, dep === null || dep === void 0 ? void 0 : dep.options).apply(childCompiler);
|
|
680
822
|
}
|
|
681
823
|
this.pages.forEach(item => {
|
|
682
824
|
if (item.path === pagePath) {
|
|
@@ -697,6 +839,13 @@ class TaroMiniPlugin {
|
|
|
697
839
|
// 添加 comp 和 custom-wrapper 组件
|
|
698
840
|
new TaroSingleEntryPlugin_1.default(compiler.context, path_1.default.resolve(__dirname, '..', 'template/comp'), `${name}/comp`, helper_1.META_TYPE.STATIC).apply(childCompiler);
|
|
699
841
|
new TaroSingleEntryPlugin_1.default(compiler.context, path_1.default.resolve(__dirname, '..', 'template/custom-wrapper'), `${name}/custom-wrapper`, helper_1.META_TYPE.STATIC).apply(childCompiler);
|
|
842
|
+
// 给每个子编译器标记上名称和 tag
|
|
843
|
+
// tag 用于生成模板和 config 时区别于主编译器走不同的方法
|
|
844
|
+
// 名称用于在生成资源时判断是否为当前子编译器的资源
|
|
845
|
+
childCompiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
846
|
+
compilation.__name = name;
|
|
847
|
+
compilation.__tag = CHILD_COMPILER_TAG;
|
|
848
|
+
});
|
|
700
849
|
promises.push(new Promise((resolve, reject) => {
|
|
701
850
|
childCompiler.runAsChild(err => {
|
|
702
851
|
if (err) {
|
|
@@ -755,38 +904,109 @@ class TaroMiniPlugin {
|
|
|
755
904
|
getShowPath(filePath) {
|
|
756
905
|
return filePath.replace(this.context, '').replace(/\\/g, '/').replace(/^\//, '');
|
|
757
906
|
}
|
|
907
|
+
// 调整 config 文件中 usingComponents 的路径
|
|
908
|
+
// 1. 将 node_modules 调整为 npm
|
|
909
|
+
// 2. 将 ../../../node_modules/xxx 调整为 /npm/xxx
|
|
910
|
+
adjustConfigContent(config) {
|
|
911
|
+
const { usingComponents } = config;
|
|
912
|
+
if (!usingComponents || this.options.skipProcessUsingComponents)
|
|
913
|
+
return;
|
|
914
|
+
for (const [key, value] of Object.entries(usingComponents)) {
|
|
915
|
+
if (!value.includes(helper_1.NODE_MODULES))
|
|
916
|
+
return;
|
|
917
|
+
const match = value.replace(helper_1.NODE_MODULES, 'npm').match(/npm.*/);
|
|
918
|
+
usingComponents[key] = match ? `${path_1.default.sep}${match[0]}` : value;
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
/** 生成小程序独立分包的相关文件 */
|
|
922
|
+
generateIndependentMiniFiles(compilation, compiler) {
|
|
923
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
924
|
+
const { template, isBuildPlugin, sourceDir } = this.options;
|
|
925
|
+
const baseTemplateName = this.getIsBuildPluginPath('base', isBuildPlugin);
|
|
926
|
+
const isUsingCustomWrapper = component_1.componentConfig.thirdPartyComponents.has('custom-wrapper');
|
|
927
|
+
// @ts-ignore
|
|
928
|
+
const childName = compilation.__name;
|
|
929
|
+
// 为独立分包生成 base/comp/custom-wrapper
|
|
930
|
+
this.independentPackages.forEach((_pages, name) => {
|
|
931
|
+
// independentPackages 是包含了所有 ChildCompiler 的资源,如果不是当前 ChildCompiler 的资源不做处理
|
|
932
|
+
if (name !== childName)
|
|
933
|
+
return;
|
|
934
|
+
this.generateTemplateFile(compilation, compiler, `${name}/${baseTemplateName}`, template.buildTemplate, component_1.componentConfig);
|
|
935
|
+
if (!template.isSupportRecursive) {
|
|
936
|
+
// 如微信、QQ 不支持递归模版的小程序,需要使用自定义组件协助递归
|
|
937
|
+
this.generateConfigFile(compilation, compiler, `${name}/${baseCompName}`, {
|
|
938
|
+
component: true,
|
|
939
|
+
usingComponents: {
|
|
940
|
+
[baseCompName]: `./${baseCompName}`,
|
|
941
|
+
[customWrapperName]: `./${customWrapperName}`
|
|
942
|
+
}
|
|
943
|
+
});
|
|
944
|
+
this.generateTemplateFile(compilation, compiler, `${name}/${baseCompName}`, template.buildBaseComponentTemplate, this.options.fileType.templ);
|
|
945
|
+
}
|
|
946
|
+
this.generateConfigFile(compilation, compiler, `${name}/${customWrapperName}`, {
|
|
947
|
+
component: true,
|
|
948
|
+
usingComponents: {
|
|
949
|
+
[customWrapperName]: `./${customWrapperName}`
|
|
950
|
+
}
|
|
951
|
+
});
|
|
952
|
+
this.generateTemplateFile(compilation, compiler, `${name}/${customWrapperName}`, template.buildCustomComponentTemplate, this.options.fileType.templ);
|
|
953
|
+
this.generateXSFile(compilation, compiler, `${name}/utils`, isBuildPlugin);
|
|
954
|
+
});
|
|
955
|
+
this.pages.forEach(page => {
|
|
956
|
+
let importBaseTemplatePath = (0, helper_1.promoteRelativePath)(path_1.default.relative(page.path, path_1.default.join(sourceDir, this.getTemplatePath(baseTemplateName))));
|
|
957
|
+
const config = this.filesConfig[this.getConfigFilePath(page.name)];
|
|
958
|
+
let isIndependent = false;
|
|
959
|
+
let independentName = '';
|
|
960
|
+
this.independentPackages.forEach((pages, name) => {
|
|
961
|
+
// independentPackages 是包含了所有 ChildCompiler 的资源,如果不是当前 ChildCompiler 的资源不做处理
|
|
962
|
+
if (pages.includes(page.path) && name === childName) {
|
|
963
|
+
isIndependent = true;
|
|
964
|
+
independentName = name;
|
|
965
|
+
importBaseTemplatePath = (0, helper_1.promoteRelativePath)(path_1.default.relative(page.path, path_1.default.join(sourceDir, name, this.getTemplatePath(baseTemplateName))));
|
|
966
|
+
}
|
|
967
|
+
});
|
|
968
|
+
if (!isIndependent)
|
|
969
|
+
return;
|
|
970
|
+
if (config) {
|
|
971
|
+
const importBaseCompPath = (0, helper_1.promoteRelativePath)(path_1.default.relative(page.path, path_1.default.join(sourceDir, independentName, this.getTargetFilePath(this.getIsBuildPluginPath(baseCompName, isBuildPlugin), ''))));
|
|
972
|
+
const importCustomWrapperPath = (0, helper_1.promoteRelativePath)(path_1.default.relative(page.path, path_1.default.join(sourceDir, independentName, this.getTargetFilePath(this.getIsBuildPluginPath(customWrapperName, isBuildPlugin), ''))));
|
|
973
|
+
config.content.usingComponents = Object.assign({}, config.content.usingComponents);
|
|
974
|
+
if (isUsingCustomWrapper) {
|
|
975
|
+
config.content.usingComponents[customWrapperName] = importCustomWrapperPath;
|
|
976
|
+
}
|
|
977
|
+
if (!template.isSupportRecursive && !page.isNative) {
|
|
978
|
+
config.content.usingComponents[baseCompName] = importBaseCompPath;
|
|
979
|
+
}
|
|
980
|
+
this.generateConfigFile(compilation, compiler, page.path, config.content);
|
|
981
|
+
}
|
|
982
|
+
if (!page.isNative) {
|
|
983
|
+
this.generateTemplateFile(compilation, compiler, page.path, template.buildPageTemplate, importBaseTemplatePath);
|
|
984
|
+
}
|
|
985
|
+
});
|
|
986
|
+
});
|
|
987
|
+
}
|
|
758
988
|
/** 生成小程序相关文件 */
|
|
759
989
|
generateMiniFiles(compilation, compiler) {
|
|
760
990
|
return __awaiter(this, void 0, void 0, function* () {
|
|
761
991
|
const { RawSource } = compiler.webpack.sources;
|
|
762
|
-
const { template,
|
|
992
|
+
const { template, modifyMiniConfigs, isBuildPlugin, sourceDir } = this.options;
|
|
763
993
|
const baseTemplateName = this.getIsBuildPluginPath('base', isBuildPlugin);
|
|
764
|
-
const baseCompName = 'comp';
|
|
765
|
-
const customWrapperName = 'custom-wrapper';
|
|
766
994
|
const isUsingCustomWrapper = component_1.componentConfig.thirdPartyComponents.has('custom-wrapper');
|
|
767
995
|
/**
|
|
768
996
|
* 与原生小程序混写时解析模板与样式
|
|
769
997
|
*/
|
|
770
998
|
compilation.getAssets().forEach(({ name: assetPath }) => {
|
|
771
999
|
const styleExt = this.options.fileType.style;
|
|
772
|
-
|
|
773
|
-
if (new RegExp(`(\\${styleExt}|\\${templExt})\\.js(\\.map){0,1}$`).test(assetPath)) {
|
|
774
|
-
delete compilation.assets[assetPath];
|
|
775
|
-
}
|
|
776
|
-
else if (new RegExp(`${styleExt}${styleExt}$`).test(assetPath)) {
|
|
1000
|
+
if (new RegExp(`${styleExt}${styleExt}$`).test(assetPath)) {
|
|
777
1001
|
const assetObj = compilation.assets[assetPath];
|
|
778
1002
|
const newAssetPath = assetPath.replace(styleExt, '');
|
|
779
1003
|
compilation.assets[newAssetPath] = assetObj;
|
|
780
|
-
delete compilation.assets[assetPath];
|
|
781
|
-
}
|
|
782
|
-
if (!isUsingCustomWrapper && assetPath === 'custom-wrapper.js') {
|
|
783
|
-
delete compilation.assets[assetPath];
|
|
784
1004
|
}
|
|
785
1005
|
});
|
|
786
1006
|
if (typeof modifyMiniConfigs === 'function') {
|
|
787
1007
|
yield modifyMiniConfigs(this.filesConfig);
|
|
788
1008
|
}
|
|
789
|
-
if (!this.options.blended && !isBuildPlugin) {
|
|
1009
|
+
if ((!this.options.blended || !this.options.newBlended) && !isBuildPlugin) {
|
|
790
1010
|
const appConfigPath = this.getConfigFilePath(this.appEntry);
|
|
791
1011
|
const appConfigName = path_1.default.basename(appConfigPath).replace(path_1.default.extname(appConfigPath), '');
|
|
792
1012
|
this.generateConfigFile(compilation, compiler, this.appEntry, this.filesConfig[appConfigName].content);
|
|
@@ -801,7 +1021,7 @@ class TaroMiniPlugin {
|
|
|
801
1021
|
}
|
|
802
1022
|
};
|
|
803
1023
|
if (isUsingCustomWrapper) {
|
|
804
|
-
baseCompConfig[customWrapperName] = `./${customWrapperName}`;
|
|
1024
|
+
baseCompConfig.usingComponents[customWrapperName] = `./${customWrapperName}`;
|
|
805
1025
|
this.generateConfigFile(compilation, compiler, this.getIsBuildPluginPath(customWrapperName, isBuildPlugin), {
|
|
806
1026
|
component: true,
|
|
807
1027
|
usingComponents: {
|
|
@@ -822,32 +1042,17 @@ class TaroMiniPlugin {
|
|
|
822
1042
|
});
|
|
823
1043
|
}
|
|
824
1044
|
}
|
|
825
|
-
|
|
1045
|
+
const buildBaseTemplate = function (...args) {
|
|
1046
|
+
const xmlsOutputDir = path_1.default.join(compiler.outputPath, './taro_xmls');
|
|
1047
|
+
const list = helper_1.fs.existsSync(xmlsOutputDir) ? helper_1.fs.readdirSync(xmlsOutputDir) : [];
|
|
1048
|
+
return list.reduce((pre, cur) => {
|
|
1049
|
+
const xmlPath = path_1.default.join(xmlsOutputDir, cur);
|
|
1050
|
+
return pre + `\n<import src="${path_1.default.relative(compiler.outputPath, xmlPath)}"/>`;
|
|
1051
|
+
}, template.buildTemplate(...args));
|
|
1052
|
+
};
|
|
1053
|
+
this.generateTemplateFile(compilation, compiler, baseTemplateName, buildBaseTemplate, component_1.componentConfig);
|
|
826
1054
|
isUsingCustomWrapper && this.generateTemplateFile(compilation, compiler, this.getIsBuildPluginPath(customWrapperName, isBuildPlugin), template.buildCustomComponentTemplate, this.options.fileType.templ);
|
|
827
1055
|
this.generateXSFile(compilation, compiler, 'utils', isBuildPlugin);
|
|
828
|
-
// 为独立分包生成 base/comp/custom-wrapper
|
|
829
|
-
this.independentPackages.forEach((_pages, name) => {
|
|
830
|
-
this.generateTemplateFile(compilation, compiler, `${name}/${baseTemplateName}`, template.buildTemplate, component_1.componentConfig);
|
|
831
|
-
if (!template.isSupportRecursive) {
|
|
832
|
-
// 如微信、QQ 不支持递归模版的小程序,需要使用自定义组件协助递归
|
|
833
|
-
this.generateConfigFile(compilation, compiler, `${name}/${baseCompName}`, {
|
|
834
|
-
component: true,
|
|
835
|
-
usingComponents: {
|
|
836
|
-
[baseCompName]: `./${baseCompName}`,
|
|
837
|
-
[customWrapperName]: `./${customWrapperName}`
|
|
838
|
-
}
|
|
839
|
-
});
|
|
840
|
-
this.generateTemplateFile(compilation, compiler, `${name}/${baseCompName}`, template.buildBaseComponentTemplate, this.options.fileType.templ);
|
|
841
|
-
}
|
|
842
|
-
this.generateConfigFile(compilation, compiler, `${name}/${customWrapperName}`, {
|
|
843
|
-
component: true,
|
|
844
|
-
usingComponents: {
|
|
845
|
-
[customWrapperName]: `./${customWrapperName}`
|
|
846
|
-
}
|
|
847
|
-
});
|
|
848
|
-
this.generateTemplateFile(compilation, compiler, `${name}/${customWrapperName}`, template.buildCustomComponentTemplate, this.options.fileType.templ);
|
|
849
|
-
this.generateXSFile(compilation, compiler, `${name}/utils`, isBuildPlugin);
|
|
850
|
-
});
|
|
851
1056
|
this.components.forEach(component => {
|
|
852
1057
|
const importBaseTemplatePath = (0, helper_1.promoteRelativePath)(path_1.default.relative(component.path, path_1.default.join(sourceDir, this.getTemplatePath(baseTemplateName))));
|
|
853
1058
|
const config = this.filesConfig[this.getConfigFilePath(component.name)];
|
|
@@ -859,24 +1064,20 @@ class TaroMiniPlugin {
|
|
|
859
1064
|
}
|
|
860
1065
|
});
|
|
861
1066
|
this.pages.forEach(page => {
|
|
862
|
-
|
|
1067
|
+
const importBaseTemplatePath = (0, helper_1.promoteRelativePath)(path_1.default.relative(page.path, path_1.default.join(sourceDir, this.getTemplatePath(baseTemplateName))));
|
|
863
1068
|
const config = this.filesConfig[this.getConfigFilePath(page.name)];
|
|
864
1069
|
let isIndependent = false;
|
|
865
|
-
|
|
866
|
-
this.independentPackages.forEach(
|
|
1070
|
+
// pages 里面会混合独立分包的,在这里需要过滤一下,避免重复生成 assets
|
|
1071
|
+
this.independentPackages.forEach(pages => {
|
|
867
1072
|
if (pages.includes(page.path)) {
|
|
868
1073
|
isIndependent = true;
|
|
869
|
-
independentName = name;
|
|
870
|
-
importBaseTemplatePath = (0, helper_1.promoteRelativePath)(path_1.default.relative(page.path, path_1.default.join(sourceDir, name, this.getTemplatePath(baseTemplateName))));
|
|
871
1074
|
}
|
|
872
1075
|
});
|
|
1076
|
+
if (isIndependent)
|
|
1077
|
+
return;
|
|
873
1078
|
if (config) {
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
if (isIndependent) {
|
|
877
|
-
importBaseCompPath = (0, helper_1.promoteRelativePath)(path_1.default.relative(page.path, path_1.default.join(sourceDir, independentName, this.getTargetFilePath(this.getIsBuildPluginPath(baseCompName, isBuildPlugin), ''))));
|
|
878
|
-
importCustomWrapperPath = (0, helper_1.promoteRelativePath)(path_1.default.relative(page.path, path_1.default.join(sourceDir, independentName, this.getTargetFilePath(this.getIsBuildPluginPath(customWrapperName, isBuildPlugin), ''))));
|
|
879
|
-
}
|
|
1079
|
+
const importBaseCompPath = (0, helper_1.promoteRelativePath)(path_1.default.relative(page.path, path_1.default.join(sourceDir, this.getTargetFilePath(this.getIsBuildPluginPath(baseCompName, isBuildPlugin), ''))));
|
|
1080
|
+
const importCustomWrapperPath = (0, helper_1.promoteRelativePath)(path_1.default.relative(page.path, path_1.default.join(sourceDir, this.getTargetFilePath(this.getIsBuildPluginPath(customWrapperName, isBuildPlugin), ''))));
|
|
880
1081
|
config.content.usingComponents = Object.assign({}, config.content.usingComponents);
|
|
881
1082
|
if (isUsingCustomWrapper) {
|
|
882
1083
|
config.content.usingComponents[customWrapperName] = importCustomWrapperPath;
|
|
@@ -904,9 +1105,27 @@ class TaroMiniPlugin {
|
|
|
904
1105
|
compilation.assets[relativePath] = new RawSource(JSON.stringify(pluginJSON));
|
|
905
1106
|
}
|
|
906
1107
|
}
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
1108
|
+
});
|
|
1109
|
+
}
|
|
1110
|
+
optimizeMiniFiles(compilation, _compiler) {
|
|
1111
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1112
|
+
const isUsingCustomWrapper = component_1.componentConfig.thirdPartyComponents.has('custom-wrapper');
|
|
1113
|
+
/**
|
|
1114
|
+
* 与原生小程序混写时解析模板与样式
|
|
1115
|
+
*/
|
|
1116
|
+
compilation.getAssets().forEach(({ name: assetPath }) => {
|
|
1117
|
+
const styleExt = this.options.fileType.style;
|
|
1118
|
+
const templExt = this.options.fileType.templ;
|
|
1119
|
+
if (new RegExp(`(\\${styleExt}|\\${templExt})\\.js(\\.map){0,1}$`).test(assetPath)) {
|
|
1120
|
+
delete compilation.assets[assetPath];
|
|
1121
|
+
}
|
|
1122
|
+
else if (new RegExp(`${styleExt}${styleExt}$`).test(assetPath)) {
|
|
1123
|
+
delete compilation.assets[assetPath];
|
|
1124
|
+
}
|
|
1125
|
+
if (!isUsingCustomWrapper && assetPath === 'custom-wrapper.js') {
|
|
1126
|
+
delete compilation.assets[assetPath];
|
|
1127
|
+
}
|
|
1128
|
+
});
|
|
910
1129
|
});
|
|
911
1130
|
}
|
|
912
1131
|
generateConfigFile(compilation, compiler, filePath, config) {
|
|
@@ -916,6 +1135,7 @@ class TaroMiniPlugin {
|
|
|
916
1135
|
unofficialConfigs.forEach(item => {
|
|
917
1136
|
delete config[item];
|
|
918
1137
|
});
|
|
1138
|
+
this.adjustConfigContent(config);
|
|
919
1139
|
const fileConfigStr = JSON.stringify(config);
|
|
920
1140
|
compilation.assets[fileConfigName] = new RawSource(fileConfigStr);
|
|
921
1141
|
}
|
|
@@ -1015,17 +1235,25 @@ class TaroMiniPlugin {
|
|
|
1015
1235
|
* 小程序全局样式文件中引入 common chunks 中的公共样式文件
|
|
1016
1236
|
*/
|
|
1017
1237
|
injectCommonStyles({ assets }, { webpack }) {
|
|
1238
|
+
const { newBlended } = this.options;
|
|
1018
1239
|
const { ConcatSource, RawSource } = webpack.sources;
|
|
1019
1240
|
const styleExt = this.options.fileType.style;
|
|
1020
1241
|
const appStyle = `app${styleExt}`;
|
|
1021
1242
|
const REG_STYLE_EXT = new RegExp(`\\.(${styleExt.replace('.', '')})(\\?.*)?$`);
|
|
1022
1243
|
const originSource = assets[appStyle] || new RawSource('');
|
|
1023
1244
|
const commons = new ConcatSource('');
|
|
1245
|
+
const componentCommons = [];
|
|
1246
|
+
const independentPackageNames = [];
|
|
1247
|
+
this.independentPackages.forEach((_, name) => { independentPackageNames.push(name); });
|
|
1024
1248
|
Object.keys(assets).forEach(assetName => {
|
|
1025
1249
|
const fileName = path_1.default.basename(assetName, path_1.default.extname(assetName));
|
|
1026
|
-
if ((helper_1.REG_STYLE.test(assetName) || REG_STYLE_EXT.test(assetName))
|
|
1250
|
+
if ((helper_1.REG_STYLE.test(assetName) || REG_STYLE_EXT.test(assetName))
|
|
1251
|
+
&& this.options.commonChunks.includes(fileName)
|
|
1252
|
+
// app.wxss 不能引入独立分包中的 common 样式文件
|
|
1253
|
+
&& independentPackageNames.every(name => !assetName.includes(name))) {
|
|
1027
1254
|
commons.add('\n');
|
|
1028
1255
|
commons.add(`@import ${JSON.stringify((0, loader_utils_1.urlToRequest)(assetName))};`);
|
|
1256
|
+
componentCommons.push(assetName);
|
|
1029
1257
|
}
|
|
1030
1258
|
});
|
|
1031
1259
|
if (commons.size() > 0) {
|
|
@@ -1036,6 +1264,36 @@ class TaroMiniPlugin {
|
|
|
1036
1264
|
source.add(commons);
|
|
1037
1265
|
source.add('\n');
|
|
1038
1266
|
assets[appStyle] = source;
|
|
1267
|
+
if (newBlended) {
|
|
1268
|
+
// 本地化组件引入common公共样式文件
|
|
1269
|
+
this.pages.forEach(page => {
|
|
1270
|
+
if (page.isNative)
|
|
1271
|
+
return;
|
|
1272
|
+
const pageStyle = `${page.name}${styleExt}`;
|
|
1273
|
+
if (this.nativeComponents.has(page.name)) {
|
|
1274
|
+
// 本地化组件如果没有wxss则直接写入一个空的
|
|
1275
|
+
if (!(pageStyle in assets)) {
|
|
1276
|
+
assets[pageStyle] = new ConcatSource('');
|
|
1277
|
+
}
|
|
1278
|
+
const source = new ConcatSource('');
|
|
1279
|
+
const originSource = assets[pageStyle];
|
|
1280
|
+
componentCommons.forEach(item => {
|
|
1281
|
+
source.add(`@import ${JSON.stringify((0, loader_utils_1.urlToRequest)(path_1.default.relative(path_1.default.dirname(pageStyle), item)))};\n`);
|
|
1282
|
+
});
|
|
1283
|
+
source.add(originSource);
|
|
1284
|
+
assets[pageStyle] = source;
|
|
1285
|
+
}
|
|
1286
|
+
else {
|
|
1287
|
+
if (pageStyle in assets) {
|
|
1288
|
+
const source = new ConcatSource('');
|
|
1289
|
+
const originSource = assets[pageStyle];
|
|
1290
|
+
source.add(`@import ${JSON.stringify((0, loader_utils_1.urlToRequest)(path_1.default.relative(path_1.default.dirname(pageStyle), 'app.wxss')))};\n`);
|
|
1291
|
+
source.add(originSource);
|
|
1292
|
+
assets[pageStyle] = source;
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
});
|
|
1296
|
+
}
|
|
1039
1297
|
}
|
|
1040
1298
|
}
|
|
1041
1299
|
addTarBarFilesToDependencies(compilation) {
|