@tarojs/webpack5-runner 3.8.0-canary.0 → 3.8.0-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +14 -0
- package/dist/index.h5.js +34 -22
- package/dist/index.h5.js.map +1 -1
- package/dist/index.mini.js +12 -2
- package/dist/index.mini.js.map +1 -1
- package/dist/loaders/miniCompilerLoader.js +60 -48
- package/dist/loaders/miniCompilerLoader.js.map +1 -1
- package/dist/loaders/miniTemplateLoader.js +1 -1
- package/dist/loaders/miniTemplateLoader.js.map +1 -1
- package/dist/loaders/miniXScriptLoader.js.map +1 -1
- package/dist/plugins/BuildNativePlugin.js +18 -7
- package/dist/plugins/BuildNativePlugin.js.map +1 -1
- package/dist/plugins/H5Plugin.js +9 -2
- package/dist/plugins/H5Plugin.js.map +1 -1
- package/dist/plugins/MiniCompileModePlugin.js +317 -0
- package/dist/plugins/MiniCompileModePlugin.js.map +1 -0
- package/dist/plugins/MiniPlugin.js +150 -128
- package/dist/plugins/MiniPlugin.js.map +1 -1
- package/dist/plugins/MiniSplitChunksPlugin.js +10 -3
- package/dist/plugins/MiniSplitChunksPlugin.js.map +1 -1
- package/dist/plugins/TaroComponentsExportsPlugin.js +2 -2
- package/dist/plugins/TaroComponentsExportsPlugin.js.map +1 -1
- package/dist/plugins/TaroNormalModulesPlugin.js +13 -5
- package/dist/plugins/TaroNormalModulesPlugin.js.map +1 -1
- package/dist/utils/app.js +4 -2
- package/dist/utils/app.js.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/webpack.js +7 -1
- package/dist/utils/webpack.js.map +1 -1
- package/dist/webpack/BaseConfig.js +2 -1
- package/dist/webpack/BaseConfig.js.map +1 -1
- package/dist/webpack/BuildNativePlugin.js +3 -11
- package/dist/webpack/BuildNativePlugin.js.map +1 -1
- package/dist/webpack/Combination.js +2 -2
- package/dist/webpack/Combination.js.map +1 -1
- package/dist/webpack/H5BaseConfig.js +31 -5
- package/dist/webpack/H5BaseConfig.js.map +1 -1
- package/dist/webpack/H5Combination.js +31 -3
- package/dist/webpack/H5Combination.js.map +1 -1
- package/dist/webpack/H5WebpackModule.js +9 -22
- package/dist/webpack/H5WebpackModule.js.map +1 -1
- package/dist/webpack/H5WebpackPlugin.js +8 -1
- package/dist/webpack/H5WebpackPlugin.js.map +1 -1
- package/dist/webpack/MiniCombination.js +11 -5
- package/dist/webpack/MiniCombination.js.map +1 -1
- package/dist/webpack/MiniWebpackModule.js +17 -19
- package/dist/webpack/MiniWebpackModule.js.map +1 -1
- package/dist/webpack/MiniWebpackPlugin.js +16 -42
- package/dist/webpack/MiniWebpackPlugin.js.map +1 -1
- package/index.js +1 -1
- package/package.json +26 -22
|
@@ -31,7 +31,7 @@ function isLoaderExist(loaders, loaderName) {
|
|
|
31
31
|
return loaders.some(item => item.loader === loaderName);
|
|
32
32
|
}
|
|
33
33
|
class TaroMiniPlugin {
|
|
34
|
-
constructor(options
|
|
34
|
+
constructor(options) {
|
|
35
35
|
/** app、页面、组件的配置集合 */
|
|
36
36
|
this.filesConfig = {};
|
|
37
37
|
this.isWatch = false;
|
|
@@ -42,29 +42,35 @@ class TaroMiniPlugin {
|
|
|
42
42
|
this.nativeComponents = new Map();
|
|
43
43
|
/** tabbar icon 图片路径列表 */
|
|
44
44
|
this.tabBarIcons = new Set();
|
|
45
|
+
this.prerenderPages = new Set();
|
|
45
46
|
this.dependencies = new Map();
|
|
46
47
|
this.pageLoaderName = '@tarojs/taro-loader/lib/page';
|
|
47
48
|
this.independentPackages = new Map();
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
49
|
+
const { combination } = options;
|
|
50
|
+
const miniBuildConfig = combination.config;
|
|
51
|
+
const { template, baseLevel = 16 } = miniBuildConfig;
|
|
52
|
+
this.options = {
|
|
53
|
+
sourceDir: combination.sourceDir,
|
|
54
|
+
framework: miniBuildConfig.framework || 'react',
|
|
55
|
+
frameworkExts: miniBuildConfig.frameworkExts || [],
|
|
56
|
+
template,
|
|
57
|
+
runtimePath: miniBuildConfig.runtimePath || '',
|
|
58
|
+
isBuildPlugin: miniBuildConfig.isBuildPlugin || false,
|
|
59
|
+
blended: miniBuildConfig.blended || false,
|
|
60
|
+
newBlended: miniBuildConfig.newBlended || false,
|
|
61
|
+
logger: miniBuildConfig.logger,
|
|
62
|
+
skipProcessUsingComponents: miniBuildConfig.skipProcessUsingComponents || false,
|
|
63
|
+
fileType: miniBuildConfig.fileType,
|
|
64
|
+
combination,
|
|
65
|
+
commonChunks: options.commonChunks || ['runtime', 'vendors'],
|
|
66
|
+
constantsReplaceList: options.constantsReplaceList,
|
|
67
|
+
pxTransformConfig: options.pxTransformConfig,
|
|
68
|
+
hot: options.hot,
|
|
69
|
+
loaderMeta: options.loaderMeta || {},
|
|
70
|
+
};
|
|
64
71
|
if (template.isSupportRecursive === false && baseLevel > 0) {
|
|
65
72
|
template.baseLevel = baseLevel;
|
|
66
73
|
}
|
|
67
|
-
this.prerenderPages = new Set();
|
|
68
74
|
}
|
|
69
75
|
/**
|
|
70
76
|
* 自动驱动 tapAsync
|
|
@@ -86,14 +92,15 @@ class TaroMiniPlugin {
|
|
|
86
92
|
apply(compiler) {
|
|
87
93
|
this.context = compiler.context;
|
|
88
94
|
this.appEntry = this.getAppEntry(compiler);
|
|
89
|
-
const { commonChunks,
|
|
95
|
+
const { commonChunks, combination, framework, isBuildPlugin, newBlended, } = this.options;
|
|
96
|
+
const { addChunkPages, onCompilerMake, modifyBuildAssets, onParseCreateElement, } = combination.config;
|
|
90
97
|
/** build mode */
|
|
91
98
|
compiler.hooks.run.tapAsync(PLUGIN_NAME, this.tryAsync((compiler) => __awaiter(this, void 0, void 0, function* () {
|
|
92
99
|
yield this.run(compiler);
|
|
93
100
|
new TaroLoadChunksPlugin_1.default({
|
|
94
101
|
commonChunks: commonChunks,
|
|
95
102
|
isBuildPlugin,
|
|
96
|
-
addChunkPages
|
|
103
|
+
addChunkPages,
|
|
97
104
|
pages: this.pages,
|
|
98
105
|
framework: framework
|
|
99
106
|
}).apply(compiler);
|
|
@@ -109,7 +116,7 @@ class TaroMiniPlugin {
|
|
|
109
116
|
this.loadChunksPlugin = new TaroLoadChunksPlugin_1.default({
|
|
110
117
|
commonChunks: commonChunks,
|
|
111
118
|
isBuildPlugin,
|
|
112
|
-
addChunkPages
|
|
119
|
+
addChunkPages,
|
|
113
120
|
pages: this.pages,
|
|
114
121
|
framework: framework
|
|
115
122
|
});
|
|
@@ -118,7 +125,6 @@ class TaroMiniPlugin {
|
|
|
118
125
|
})));
|
|
119
126
|
/** compilation.addEntry */
|
|
120
127
|
compiler.hooks.make.tapAsync(PLUGIN_NAME, this.tryAsync((compilation) => __awaiter(this, void 0, void 0, function* () {
|
|
121
|
-
var _a, _b;
|
|
122
128
|
const dependencies = this.dependencies;
|
|
123
129
|
const promises = [];
|
|
124
130
|
this.compileIndependentPages(compiler, compilation, dependencies, promises);
|
|
@@ -128,7 +134,7 @@ class TaroMiniPlugin {
|
|
|
128
134
|
}));
|
|
129
135
|
});
|
|
130
136
|
yield Promise.all(promises);
|
|
131
|
-
yield (
|
|
137
|
+
yield (onCompilerMake === null || onCompilerMake === void 0 ? void 0 : onCompilerMake(compilation, compiler, this));
|
|
132
138
|
})));
|
|
133
139
|
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation, { normalModuleFactory }) => {
|
|
134
140
|
/** For Webpack compilation get factory from compilation.dependencyFactories by denpendence's constructor */
|
|
@@ -160,7 +166,7 @@ class TaroMiniPlugin {
|
|
|
160
166
|
}
|
|
161
167
|
else if (module.miniType === helper_1.META_TYPE.PAGE) {
|
|
162
168
|
let isIndependent = false;
|
|
163
|
-
this.independentPackages.forEach(pages => {
|
|
169
|
+
this.independentPackages.forEach(({ pages }) => {
|
|
164
170
|
if (pages.includes(module.resource)) {
|
|
165
171
|
isIndependent = true;
|
|
166
172
|
}
|
|
@@ -230,7 +236,6 @@ class TaroMiniPlugin {
|
|
|
230
236
|
// 该 stage 是最后执行的,确保 taro 暴露给用户的钩子 modifyBuildAssets 在内部处理完 assets 之后再调用
|
|
231
237
|
stage: PROCESS_ASSETS_STAGE_REPORT
|
|
232
238
|
}, this.tryAsync(() => __awaiter(this, void 0, void 0, function* () {
|
|
233
|
-
const { modifyBuildAssets } = this.options;
|
|
234
239
|
if (typeof modifyBuildAssets === 'function') {
|
|
235
240
|
yield modifyBuildAssets(compilation.assets, this);
|
|
236
241
|
}
|
|
@@ -239,7 +244,7 @@ class TaroMiniPlugin {
|
|
|
239
244
|
compiler.hooks.afterEmit.tapAsync(PLUGIN_NAME, this.tryAsync((compilation) => __awaiter(this, void 0, void 0, function* () {
|
|
240
245
|
yield this.addTarBarFilesToDependencies(compilation);
|
|
241
246
|
})));
|
|
242
|
-
new TaroNormalModulesPlugin_1.default(
|
|
247
|
+
new TaroNormalModulesPlugin_1.default(onParseCreateElement).apply(compiler);
|
|
243
248
|
newBlended && this.addLoadChunksPlugin(compiler);
|
|
244
249
|
}
|
|
245
250
|
addLoadChunksPlugin(compiler) {
|
|
@@ -306,10 +311,6 @@ class TaroMiniPlugin {
|
|
|
306
311
|
compiler.options.entry = {};
|
|
307
312
|
return entryCopy;
|
|
308
313
|
}
|
|
309
|
-
if (this.options.appEntry) {
|
|
310
|
-
compiler.options.entry = {};
|
|
311
|
-
return this.options.appEntry;
|
|
312
|
-
}
|
|
313
314
|
function getEntryPath(entry) {
|
|
314
315
|
const app = entry.app;
|
|
315
316
|
if (Array.isArray(app)) {
|
|
@@ -324,6 +325,14 @@ class TaroMiniPlugin {
|
|
|
324
325
|
compiler.options.entry = {};
|
|
325
326
|
return appEntryPath;
|
|
326
327
|
}
|
|
328
|
+
getIndependentPackage(pagePath) {
|
|
329
|
+
return Array.from(this.independentPackages.values()).find(independentPackage => {
|
|
330
|
+
const { pages } = independentPackage;
|
|
331
|
+
if (pages.includes(pagePath)) {
|
|
332
|
+
return independentPackage;
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
}
|
|
327
336
|
getChangedFiles(compiler) {
|
|
328
337
|
return compiler.modifiedFiles;
|
|
329
338
|
}
|
|
@@ -332,26 +341,29 @@ class TaroMiniPlugin {
|
|
|
332
341
|
* 往 this.dependencies 中添加资源模块
|
|
333
342
|
*/
|
|
334
343
|
run(compiler) {
|
|
335
|
-
|
|
336
|
-
this.
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
344
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
345
|
+
if (this.options.isBuildPlugin) {
|
|
346
|
+
this.getPluginFiles();
|
|
347
|
+
this.getConfigFiles(compiler);
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
this.appConfig = yield this.getAppConfig();
|
|
351
|
+
this.getPages();
|
|
352
|
+
this.getPagesConfig();
|
|
353
|
+
this.getDarkMode();
|
|
354
|
+
this.getConfigFiles(compiler);
|
|
355
|
+
this.addEntries();
|
|
356
|
+
}
|
|
357
|
+
});
|
|
347
358
|
}
|
|
348
359
|
getPluginFiles() {
|
|
349
360
|
const fileList = new Set();
|
|
350
|
-
const {
|
|
361
|
+
const { template, combination } = this.options;
|
|
362
|
+
const { pluginConfig, pluginMainEntry } = combination.buildNativePlugin;
|
|
351
363
|
const normalFiles = new Set();
|
|
352
364
|
Object.keys(this.appEntry).forEach(key => {
|
|
353
365
|
const filePath = this.appEntry[key][0] || this.appEntry[key].import[0];
|
|
354
|
-
if (key ===
|
|
366
|
+
if (key === pluginMainEntry) {
|
|
355
367
|
this.addEntry(filePath, key, helper_1.META_TYPE.EXPORTS);
|
|
356
368
|
}
|
|
357
369
|
if (pluginConfig) {
|
|
@@ -365,14 +377,14 @@ class TaroMiniPlugin {
|
|
|
365
377
|
Object.keys(pluginConfig).forEach(pluginKey => {
|
|
366
378
|
if (pluginKey === 'pages') {
|
|
367
379
|
Object.keys(pluginConfig[pluginKey]).forEach(pageKey => {
|
|
368
|
-
if (
|
|
380
|
+
if (`${pluginConfig[pluginKey][pageKey]}` === key) {
|
|
369
381
|
isPage = true;
|
|
370
382
|
}
|
|
371
383
|
});
|
|
372
384
|
}
|
|
373
385
|
if (pluginKey === 'publicComponents') {
|
|
374
386
|
Object.keys(pluginConfig[pluginKey]).forEach(pageKey => {
|
|
375
|
-
if (
|
|
387
|
+
if (`${pluginConfig[pluginKey][pageKey]}` === key) {
|
|
376
388
|
isComponent = true;
|
|
377
389
|
}
|
|
378
390
|
});
|
|
@@ -402,9 +414,9 @@ class TaroMiniPlugin {
|
|
|
402
414
|
}
|
|
403
415
|
});
|
|
404
416
|
if (!template.isSupportRecursive) {
|
|
405
|
-
this.addEntry(path_1.default.resolve(__dirname, '..', 'template/comp'),
|
|
417
|
+
this.addEntry(path_1.default.resolve(__dirname, '..', 'template/comp'), 'comp', helper_1.META_TYPE.STATIC);
|
|
406
418
|
}
|
|
407
|
-
this.addEntry(path_1.default.resolve(__dirname, '..', 'template/custom-wrapper'),
|
|
419
|
+
this.addEntry(path_1.default.resolve(__dirname, '..', 'template/custom-wrapper'), 'custom-wrapper', helper_1.META_TYPE.STATIC);
|
|
408
420
|
normalFiles.forEach(item => {
|
|
409
421
|
this.addEntry(item.path, item.name, helper_1.META_TYPE.NORMAL, {
|
|
410
422
|
library: {
|
|
@@ -469,18 +481,24 @@ class TaroMiniPlugin {
|
|
|
469
481
|
* @returns app config 配置内容
|
|
470
482
|
*/
|
|
471
483
|
getAppConfig() {
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
484
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
485
|
+
const appName = path_1.default.basename(this.appEntry).replace(path_1.default.extname(this.appEntry), '');
|
|
486
|
+
this.compileFile({
|
|
487
|
+
name: appName,
|
|
488
|
+
path: this.appEntry,
|
|
489
|
+
isNative: false
|
|
490
|
+
});
|
|
491
|
+
const fileConfig = this.filesConfig[this.getConfigFilePath(appName)];
|
|
492
|
+
const appConfig = fileConfig ? fileConfig.content || {} : {};
|
|
493
|
+
if ((0, helper_1.isEmptyObject)(appConfig)) {
|
|
494
|
+
throw new Error('缺少 app 全局配置文件,请检查!');
|
|
495
|
+
}
|
|
496
|
+
const { modifyAppConfig } = this.options.combination.config;
|
|
497
|
+
if (typeof modifyAppConfig === 'function') {
|
|
498
|
+
yield modifyAppConfig(appConfig);
|
|
499
|
+
}
|
|
500
|
+
return appConfig;
|
|
477
501
|
});
|
|
478
|
-
const fileConfig = this.filesConfig[this.getConfigFilePath(appName)];
|
|
479
|
-
const appConfig = fileConfig ? fileConfig.content || {} : {};
|
|
480
|
-
if ((0, helper_1.isEmptyObject)(appConfig)) {
|
|
481
|
-
throw new Error('缺少 app 全局配置文件,请检查!');
|
|
482
|
-
}
|
|
483
|
-
return appConfig;
|
|
484
502
|
}
|
|
485
503
|
/**
|
|
486
504
|
* 根据 app config 的 pages 配置项,收集所有页面信息,
|
|
@@ -488,7 +506,6 @@ class TaroMiniPlugin {
|
|
|
488
506
|
*/
|
|
489
507
|
getPages() {
|
|
490
508
|
var _a;
|
|
491
|
-
const { newBlended } = this.options;
|
|
492
509
|
if ((0, helper_1.isEmptyObject)(this.appConfig)) {
|
|
493
510
|
throw new Error('缺少 app 全局配置文件,请检查!');
|
|
494
511
|
}
|
|
@@ -499,7 +516,8 @@ class TaroMiniPlugin {
|
|
|
499
516
|
if (!this.isWatch && ((_a = this.options.logger) === null || _a === void 0 ? void 0 : _a.quiet) === false) {
|
|
500
517
|
(0, helper_1.printLog)("compile" /* processTypeEnum.COMPILE */, '发现入口', this.getShowPath(this.appEntry));
|
|
501
518
|
}
|
|
502
|
-
const { frameworkExts,
|
|
519
|
+
const { newBlended, frameworkExts, combination } = this.options;
|
|
520
|
+
const { prerender } = combination.config;
|
|
503
521
|
this.prerenderPages = new Set((0, prerender_1.validatePrerenderPages)(appPages, prerender).map(p => p.path));
|
|
504
522
|
this.getTabBarFiles(this.appConfig);
|
|
505
523
|
this.pages = new Set([
|
|
@@ -551,7 +569,9 @@ class TaroMiniPlugin {
|
|
|
551
569
|
if (!this.isWatch && ((_a = this.options.logger) === null || _a === void 0 ? void 0 : _a.quiet) === false) {
|
|
552
570
|
(0, helper_1.printLog)("compile" /* processTypeEnum.COMPILE */, '发现页面', this.getShowPath(page.path));
|
|
553
571
|
}
|
|
554
|
-
|
|
572
|
+
const pagePath = page.path;
|
|
573
|
+
const independentPackage = this.getIndependentPackage(pagePath);
|
|
574
|
+
this.compileFile(page, independentPackage);
|
|
555
575
|
});
|
|
556
576
|
}
|
|
557
577
|
/**
|
|
@@ -640,12 +660,12 @@ class TaroMiniPlugin {
|
|
|
640
660
|
/**
|
|
641
661
|
* 读取页面、组件的配置,并递归读取依赖的组件的配置
|
|
642
662
|
*/
|
|
643
|
-
compileFile(file) {
|
|
663
|
+
compileFile(file, independentPackage) {
|
|
664
|
+
var _a;
|
|
644
665
|
const filePath = file.path;
|
|
645
666
|
const fileConfigPath = file.isNative ? this.replaceExt(filePath, '.json') : this.getConfigFilePath(filePath);
|
|
646
|
-
const fileConfig = (0, helper_1.readConfig)(fileConfigPath);
|
|
647
|
-
const { componentGenerics } = fileConfig;
|
|
648
|
-
const usingComponents = fileConfig.usingComponents;
|
|
667
|
+
const fileConfig = (0, helper_1.readConfig)(fileConfigPath, this.options.combination.config);
|
|
668
|
+
const { componentGenerics, usingComponents } = fileConfig;
|
|
649
669
|
if (this.options.isBuildPlugin && componentGenerics) {
|
|
650
670
|
Object.keys(componentGenerics).forEach(component => {
|
|
651
671
|
if (componentGenerics[component]) {
|
|
@@ -659,7 +679,8 @@ class TaroMiniPlugin {
|
|
|
659
679
|
if (usingComponents) {
|
|
660
680
|
const componentNames = Object.keys(usingComponents);
|
|
661
681
|
const depComponents = [];
|
|
662
|
-
|
|
682
|
+
// alias 的值需要从最终的 chain 中拿,避免用户在 webpackChain 中设置的 alias 无法被读取到
|
|
683
|
+
const alias = (_a = this.options.combination.chain.toConfig().resolve) === null || _a === void 0 ? void 0 : _a.alias;
|
|
663
684
|
for (const compName of componentNames) {
|
|
664
685
|
let compPath = usingComponents[compName];
|
|
665
686
|
if ((0, helper_1.isAliasPath)(compPath, alias)) {
|
|
@@ -668,9 +689,9 @@ class TaroMiniPlugin {
|
|
|
668
689
|
}
|
|
669
690
|
// 判断是否为第三方依赖的正则,如果 test 为 false 则为第三方依赖
|
|
670
691
|
const notNpmPkgReg = /^[.\\/]/;
|
|
671
|
-
if (!this.options.skipProcessUsingComponents
|
|
672
|
-
|
|
673
|
-
|
|
692
|
+
if (!this.options.skipProcessUsingComponents &&
|
|
693
|
+
!compPath.startsWith('plugin://') &&
|
|
694
|
+
!notNpmPkgReg.test(compPath)) {
|
|
674
695
|
const tempCompPath = (0, helper_1.getNpmPackageAbsolutePath)(compPath);
|
|
675
696
|
if (tempCompPath) {
|
|
676
697
|
compPath = tempCompPath;
|
|
@@ -686,6 +707,7 @@ class TaroMiniPlugin {
|
|
|
686
707
|
}
|
|
687
708
|
}
|
|
688
709
|
depComponents.forEach(item => {
|
|
710
|
+
var _a;
|
|
689
711
|
const componentPath = (0, helper_1.resolveMainFilePath)(path_1.default.resolve(path_1.default.dirname(file.path), item.path));
|
|
690
712
|
if (helper_1.fs.existsSync(componentPath) && !Array.from(this.components).some(item => item.path === componentPath)) {
|
|
691
713
|
const componentName = this.getComponentName(componentPath);
|
|
@@ -701,8 +723,10 @@ class TaroMiniPlugin {
|
|
|
701
723
|
stylePath: isNative ? this.getStylePath(componentPath) : undefined,
|
|
702
724
|
templatePath: isNative ? this.getTemplatePath(componentPath) : undefined
|
|
703
725
|
};
|
|
726
|
+
// 收集独立分包的组件,用于后续单独编译
|
|
727
|
+
(_a = independentPackage === null || independentPackage === void 0 ? void 0 : independentPackage.components) === null || _a === void 0 ? void 0 : _a.push(componentPath);
|
|
704
728
|
this.components.add(componentObj);
|
|
705
|
-
this.compileFile(componentObj);
|
|
729
|
+
this.compileFile(componentObj, independentPackage);
|
|
706
730
|
}
|
|
707
731
|
});
|
|
708
732
|
}
|
|
@@ -723,9 +747,10 @@ class TaroMiniPlugin {
|
|
|
723
747
|
const root = item.root;
|
|
724
748
|
const isIndependent = !!item.independent;
|
|
725
749
|
if (isIndependent) {
|
|
726
|
-
this.independentPackages.set(root, []);
|
|
750
|
+
this.independentPackages.set(root, { pages: [], components: [] });
|
|
727
751
|
}
|
|
728
752
|
item.pages.forEach(page => {
|
|
753
|
+
var _a;
|
|
729
754
|
let pageItem = `${root}/${page}`;
|
|
730
755
|
pageItem = pageItem.replace(/\/{2,}/g, '/');
|
|
731
756
|
let hasPageIn = false;
|
|
@@ -739,7 +764,7 @@ class TaroMiniPlugin {
|
|
|
739
764
|
const templatePath = this.getTemplatePath(pagePath);
|
|
740
765
|
const isNative = this.isNativePageORComponent(templatePath);
|
|
741
766
|
if (isIndependent) {
|
|
742
|
-
const independentPages = this.independentPackages.get(root);
|
|
767
|
+
const independentPages = (_a = this.independentPackages.get(root)) === null || _a === void 0 ? void 0 : _a.pages;
|
|
743
768
|
independentPages === null || independentPages === void 0 ? void 0 : independentPages.push(pagePath);
|
|
744
769
|
}
|
|
745
770
|
this.pages.add({
|
|
@@ -773,7 +798,7 @@ class TaroMiniPlugin {
|
|
|
773
798
|
const SplitChunksPlugin = require('webpack/lib/optimize/SplitChunksPlugin');
|
|
774
799
|
const RuntimeChunkPlugin = require('webpack/lib/optimize/RuntimeChunkPlugin');
|
|
775
800
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
776
|
-
independentPackages.forEach((pages, name) => {
|
|
801
|
+
independentPackages.forEach(({ pages, components }, name) => {
|
|
777
802
|
const childCompiler = compilation.createChildCompiler(PLUGIN_NAME, {
|
|
778
803
|
path: `${compiler.options.output.path}/${name}`,
|
|
779
804
|
chunkLoadingGlobal: `subpackage_${name}`
|
|
@@ -827,10 +852,17 @@ class TaroMiniPlugin {
|
|
|
827
852
|
});
|
|
828
853
|
dependencies.delete(pagePath);
|
|
829
854
|
});
|
|
855
|
+
components.forEach(componentPath => {
|
|
856
|
+
if (dependencies.has(componentPath)) {
|
|
857
|
+
const dep = dependencies.get(componentPath);
|
|
858
|
+
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);
|
|
859
|
+
}
|
|
860
|
+
dependencies.delete(componentPath);
|
|
861
|
+
});
|
|
830
862
|
new TaroLoadChunksPlugin_1.default({
|
|
831
863
|
commonChunks: [`${name}/runtime`, `${name}/vendors`, `${name}/common`],
|
|
832
864
|
isBuildPlugin: false,
|
|
833
|
-
addChunkPages: this.options.addChunkPages,
|
|
865
|
+
addChunkPages: this.options.combination.config.addChunkPages,
|
|
834
866
|
pages: childPages,
|
|
835
867
|
framework: this.options.framework,
|
|
836
868
|
isIndependentPackages: true,
|
|
@@ -921,8 +953,8 @@ class TaroMiniPlugin {
|
|
|
921
953
|
/** 生成小程序独立分包的相关文件 */
|
|
922
954
|
generateIndependentMiniFiles(compilation, compiler) {
|
|
923
955
|
return __awaiter(this, void 0, void 0, function* () {
|
|
924
|
-
const { template,
|
|
925
|
-
const baseTemplateName =
|
|
956
|
+
const { template, sourceDir } = this.options;
|
|
957
|
+
const baseTemplateName = 'base';
|
|
926
958
|
const isUsingCustomWrapper = component_1.componentConfig.thirdPartyComponents.has('custom-wrapper');
|
|
927
959
|
// @ts-ignore
|
|
928
960
|
const childName = compilation.__name;
|
|
@@ -950,14 +982,14 @@ class TaroMiniPlugin {
|
|
|
950
982
|
}
|
|
951
983
|
});
|
|
952
984
|
this.generateTemplateFile(compilation, compiler, `${name}/${customWrapperName}`, template.buildCustomComponentTemplate, this.options.fileType.templ);
|
|
953
|
-
this.generateXSFile(compilation, compiler, `${name}/utils
|
|
985
|
+
this.generateXSFile(compilation, compiler, `${name}/utils`);
|
|
954
986
|
});
|
|
955
987
|
this.pages.forEach(page => {
|
|
956
988
|
let importBaseTemplatePath = (0, helper_1.promoteRelativePath)(path_1.default.relative(page.path, path_1.default.join(sourceDir, this.getTemplatePath(baseTemplateName))));
|
|
957
989
|
const config = this.filesConfig[this.getConfigFilePath(page.name)];
|
|
958
990
|
let isIndependent = false;
|
|
959
991
|
let independentName = '';
|
|
960
|
-
this.independentPackages.forEach((pages, name) => {
|
|
992
|
+
this.independentPackages.forEach(({ pages }, name) => {
|
|
961
993
|
// independentPackages 是包含了所有 ChildCompiler 的资源,如果不是当前 ChildCompiler 的资源不做处理
|
|
962
994
|
if (pages.includes(page.path) && name === childName) {
|
|
963
995
|
isIndependent = true;
|
|
@@ -967,9 +999,13 @@ class TaroMiniPlugin {
|
|
|
967
999
|
});
|
|
968
1000
|
if (!isIndependent)
|
|
969
1001
|
return;
|
|
1002
|
+
// 生成页面模板需要在生成页面配置之前,因为会依赖到页面配置的部分内容
|
|
1003
|
+
if (!page.isNative) {
|
|
1004
|
+
this.generateTemplateFile(compilation, compiler, page.path, template.buildPageTemplate, importBaseTemplatePath, config);
|
|
1005
|
+
}
|
|
970
1006
|
if (config) {
|
|
971
|
-
const importBaseCompPath = (0, helper_1.promoteRelativePath)(path_1.default.relative(page.path, path_1.default.join(sourceDir, independentName, this.getTargetFilePath(
|
|
972
|
-
const importCustomWrapperPath = (0, helper_1.promoteRelativePath)(path_1.default.relative(page.path, path_1.default.join(sourceDir, independentName, this.getTargetFilePath(
|
|
1007
|
+
const importBaseCompPath = (0, helper_1.promoteRelativePath)(path_1.default.relative(page.path, path_1.default.join(sourceDir, independentName, this.getTargetFilePath(baseCompName, ''))));
|
|
1008
|
+
const importCustomWrapperPath = (0, helper_1.promoteRelativePath)(path_1.default.relative(page.path, path_1.default.join(sourceDir, independentName, this.getTargetFilePath(customWrapperName, ''))));
|
|
973
1009
|
config.content.usingComponents = Object.assign({}, config.content.usingComponents);
|
|
974
1010
|
if (isUsingCustomWrapper) {
|
|
975
1011
|
config.content.usingComponents[customWrapperName] = importCustomWrapperPath;
|
|
@@ -979,9 +1015,6 @@ class TaroMiniPlugin {
|
|
|
979
1015
|
}
|
|
980
1016
|
this.generateConfigFile(compilation, compiler, page.path, config.content);
|
|
981
1017
|
}
|
|
982
|
-
if (!page.isNative) {
|
|
983
|
-
this.generateTemplateFile(compilation, compiler, page.path, template.buildPageTemplate, importBaseTemplatePath);
|
|
984
|
-
}
|
|
985
1018
|
});
|
|
986
1019
|
});
|
|
987
1020
|
}
|
|
@@ -989,8 +1022,9 @@ class TaroMiniPlugin {
|
|
|
989
1022
|
generateMiniFiles(compilation, compiler) {
|
|
990
1023
|
return __awaiter(this, void 0, void 0, function* () {
|
|
991
1024
|
const { RawSource } = compiler.webpack.sources;
|
|
992
|
-
const { template,
|
|
993
|
-
const
|
|
1025
|
+
const { template, combination, isBuildPlugin, sourceDir } = this.options;
|
|
1026
|
+
const { modifyMiniConfigs } = combination.config;
|
|
1027
|
+
const baseTemplateName = 'base';
|
|
994
1028
|
const isUsingCustomWrapper = component_1.componentConfig.thirdPartyComponents.has('custom-wrapper');
|
|
995
1029
|
/**
|
|
996
1030
|
* 与原生小程序混写时解析模板与样式
|
|
@@ -1013,7 +1047,7 @@ class TaroMiniPlugin {
|
|
|
1013
1047
|
}
|
|
1014
1048
|
if (!template.isSupportRecursive) {
|
|
1015
1049
|
// 如微信、QQ 不支持递归模版的小程序,需要使用自定义组件协助递归
|
|
1016
|
-
this.generateTemplateFile(compilation, compiler,
|
|
1050
|
+
this.generateTemplateFile(compilation, compiler, baseCompName, template.buildBaseComponentTemplate, this.options.fileType.templ);
|
|
1017
1051
|
const baseCompConfig = {
|
|
1018
1052
|
component: true,
|
|
1019
1053
|
usingComponents: {
|
|
@@ -1022,19 +1056,20 @@ class TaroMiniPlugin {
|
|
|
1022
1056
|
};
|
|
1023
1057
|
if (isUsingCustomWrapper) {
|
|
1024
1058
|
baseCompConfig.usingComponents[customWrapperName] = `./${customWrapperName}`;
|
|
1025
|
-
this.generateConfigFile(compilation, compiler,
|
|
1059
|
+
this.generateConfigFile(compilation, compiler, customWrapperName, {
|
|
1026
1060
|
component: true,
|
|
1061
|
+
styleIsolation: 'apply-shared',
|
|
1027
1062
|
usingComponents: {
|
|
1028
1063
|
[baseCompName]: `./${baseCompName}`,
|
|
1029
1064
|
[customWrapperName]: `./${customWrapperName}`
|
|
1030
1065
|
}
|
|
1031
1066
|
});
|
|
1032
1067
|
}
|
|
1033
|
-
this.generateConfigFile(compilation, compiler,
|
|
1068
|
+
this.generateConfigFile(compilation, compiler, baseCompName, baseCompConfig);
|
|
1034
1069
|
}
|
|
1035
1070
|
else {
|
|
1036
1071
|
if (isUsingCustomWrapper) {
|
|
1037
|
-
this.generateConfigFile(compilation, compiler,
|
|
1072
|
+
this.generateConfigFile(compilation, compiler, customWrapperName, {
|
|
1038
1073
|
component: true,
|
|
1039
1074
|
usingComponents: {
|
|
1040
1075
|
[customWrapperName]: `./${customWrapperName}`
|
|
@@ -1042,19 +1077,11 @@ class TaroMiniPlugin {
|
|
|
1042
1077
|
});
|
|
1043
1078
|
}
|
|
1044
1079
|
}
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
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);
|
|
1054
|
-
isUsingCustomWrapper && this.generateTemplateFile(compilation, compiler, this.getIsBuildPluginPath(customWrapperName, isBuildPlugin), template.buildCustomComponentTemplate, this.options.fileType.templ);
|
|
1055
|
-
this.generateXSFile(compilation, compiler, 'utils', isBuildPlugin);
|
|
1080
|
+
this.generateTemplateFile(compilation, compiler, baseTemplateName, template.buildTemplate, component_1.componentConfig);
|
|
1081
|
+
isUsingCustomWrapper && this.generateTemplateFile(compilation, compiler, customWrapperName, template.buildCustomComponentTemplate, this.options.fileType.templ);
|
|
1082
|
+
this.generateXSFile(compilation, compiler, 'utils');
|
|
1056
1083
|
this.components.forEach(component => {
|
|
1057
|
-
const importBaseTemplatePath = (0, helper_1.promoteRelativePath)(path_1.default.relative(component.path, path_1.default.join(sourceDir, this.getTemplatePath(baseTemplateName))));
|
|
1084
|
+
const importBaseTemplatePath = (0, helper_1.promoteRelativePath)(path_1.default.relative(component.path, path_1.default.join(sourceDir, isBuildPlugin ? 'plugin' : '', this.getTemplatePath(baseTemplateName))));
|
|
1058
1085
|
const config = this.filesConfig[this.getConfigFilePath(component.name)];
|
|
1059
1086
|
if (config) {
|
|
1060
1087
|
this.generateConfigFile(compilation, compiler, component.path, config.content);
|
|
@@ -1064,20 +1091,19 @@ class TaroMiniPlugin {
|
|
|
1064
1091
|
}
|
|
1065
1092
|
});
|
|
1066
1093
|
this.pages.forEach(page => {
|
|
1067
|
-
const importBaseTemplatePath = (0, helper_1.promoteRelativePath)(path_1.default.relative(page.path, path_1.default.join(sourceDir, this.getTemplatePath(baseTemplateName))));
|
|
1094
|
+
const importBaseTemplatePath = (0, helper_1.promoteRelativePath)(path_1.default.relative(page.path, path_1.default.join(sourceDir, isBuildPlugin ? 'plugin' : '', this.getTemplatePath(baseTemplateName))));
|
|
1068
1095
|
const config = this.filesConfig[this.getConfigFilePath(page.name)];
|
|
1069
|
-
let isIndependent = false;
|
|
1070
1096
|
// pages 里面会混合独立分包的,在这里需要过滤一下,避免重复生成 assets
|
|
1071
|
-
this.
|
|
1072
|
-
if (pages.includes(page.path)) {
|
|
1073
|
-
isIndependent = true;
|
|
1074
|
-
}
|
|
1075
|
-
});
|
|
1097
|
+
const isIndependent = !!this.getIndependentPackage(page.path);
|
|
1076
1098
|
if (isIndependent)
|
|
1077
1099
|
return;
|
|
1100
|
+
// 生成页面模板需要在生成页面配置之前,因为会依赖到页面配置的部分内容
|
|
1101
|
+
if (!page.isNative) {
|
|
1102
|
+
this.generateTemplateFile(compilation, compiler, page.path, template.buildPageTemplate, importBaseTemplatePath, config);
|
|
1103
|
+
}
|
|
1078
1104
|
if (config) {
|
|
1079
|
-
const importBaseCompPath = (0, helper_1.promoteRelativePath)(path_1.default.relative(page.path, path_1.default.join(sourceDir, this.getTargetFilePath(
|
|
1080
|
-
const importCustomWrapperPath = (0, helper_1.promoteRelativePath)(path_1.default.relative(page.path, path_1.default.join(sourceDir, this.getTargetFilePath(
|
|
1105
|
+
const importBaseCompPath = (0, helper_1.promoteRelativePath)(path_1.default.relative(page.path, path_1.default.join(sourceDir, this.getTargetFilePath(baseCompName, ''))));
|
|
1106
|
+
const importCustomWrapperPath = (0, helper_1.promoteRelativePath)(path_1.default.relative(page.path, path_1.default.join(sourceDir, this.getTargetFilePath(customWrapperName, ''))));
|
|
1081
1107
|
config.content.usingComponents = Object.assign({}, config.content.usingComponents);
|
|
1082
1108
|
if (isUsingCustomWrapper) {
|
|
1083
1109
|
config.content.usingComponents[customWrapperName] = importCustomWrapperPath;
|
|
@@ -1087,9 +1113,6 @@ class TaroMiniPlugin {
|
|
|
1087
1113
|
}
|
|
1088
1114
|
this.generateConfigFile(compilation, compiler, page.path, config.content);
|
|
1089
1115
|
}
|
|
1090
|
-
if (!page.isNative) {
|
|
1091
|
-
this.generateTemplateFile(compilation, compiler, page.path, template.buildPageTemplate, importBaseTemplatePath);
|
|
1092
|
-
}
|
|
1093
1116
|
});
|
|
1094
1117
|
this.generateTabBarFiles(compilation, compiler);
|
|
1095
1118
|
this.injectCommonStyles(compilation, compiler);
|
|
@@ -1101,8 +1124,7 @@ class TaroMiniPlugin {
|
|
|
1101
1124
|
if (helper_1.fs.existsSync(pluginJSONPath)) {
|
|
1102
1125
|
const pluginJSON = helper_1.fs.readJSONSync(pluginJSONPath);
|
|
1103
1126
|
this.modifyPluginJSON(pluginJSON);
|
|
1104
|
-
|
|
1105
|
-
compilation.assets[relativePath] = new RawSource(JSON.stringify(pluginJSON));
|
|
1127
|
+
compilation.assets['plugin.json'] = new RawSource(JSON.stringify(pluginJSON));
|
|
1106
1128
|
}
|
|
1107
1129
|
}
|
|
1108
1130
|
});
|
|
@@ -1131,7 +1153,7 @@ class TaroMiniPlugin {
|
|
|
1131
1153
|
generateConfigFile(compilation, compiler, filePath, config) {
|
|
1132
1154
|
const { RawSource } = compiler.webpack.sources;
|
|
1133
1155
|
const fileConfigName = this.getConfigPath(this.getComponentName(filePath));
|
|
1134
|
-
const unofficialConfigs = ['enableShareAppMessage', 'enableShareTimeline', 'components'];
|
|
1156
|
+
const unofficialConfigs = ['enableShareAppMessage', 'enableShareTimeline', 'enablePageMeta', 'components'];
|
|
1135
1157
|
unofficialConfigs.forEach(item => {
|
|
1136
1158
|
delete config[item];
|
|
1137
1159
|
});
|
|
@@ -1144,7 +1166,7 @@ class TaroMiniPlugin {
|
|
|
1144
1166
|
const { RawSource } = compiler.webpack.sources;
|
|
1145
1167
|
let templStr = templateFn(...options);
|
|
1146
1168
|
const fileTemplName = this.getTemplatePath(this.getComponentName(filePath));
|
|
1147
|
-
if ((_a = this.options.minifyXML) === null || _a === void 0 ? void 0 : _a.collapseWhitespace) {
|
|
1169
|
+
if ((_a = this.options.combination.config.minifyXML) === null || _a === void 0 ? void 0 : _a.collapseWhitespace) {
|
|
1148
1170
|
const minify = require('html-minifier').minify;
|
|
1149
1171
|
templStr = minify(templStr, {
|
|
1150
1172
|
collapseWhitespace: true,
|
|
@@ -1153,7 +1175,7 @@ class TaroMiniPlugin {
|
|
|
1153
1175
|
}
|
|
1154
1176
|
compilation.assets[fileTemplName] = new RawSource(templStr);
|
|
1155
1177
|
}
|
|
1156
|
-
generateXSFile(compilation, compiler, xsPath
|
|
1178
|
+
generateXSFile(compilation, compiler, xsPath) {
|
|
1157
1179
|
const { RawSource } = compiler.webpack.sources;
|
|
1158
1180
|
const ext = this.options.fileType.xs;
|
|
1159
1181
|
const isSupportXS = this.options.template.supportXS;
|
|
@@ -1162,7 +1184,7 @@ class TaroMiniPlugin {
|
|
|
1162
1184
|
}
|
|
1163
1185
|
const xs = this.options.template.buildXScript();
|
|
1164
1186
|
const fileXsName = this.getTargetFilePath(xsPath, ext);
|
|
1165
|
-
const filePath =
|
|
1187
|
+
const filePath = fileXsName;
|
|
1166
1188
|
compilation.assets[filePath] = new RawSource(xs);
|
|
1167
1189
|
}
|
|
1168
1190
|
getComponentName(componentPath) {
|
|
@@ -1173,12 +1195,12 @@ class TaroMiniPlugin {
|
|
|
1173
1195
|
}
|
|
1174
1196
|
else {
|
|
1175
1197
|
componentName = componentPath.replace(this.options.sourceDir, '').replace(/\\/g, '/').replace(path_1.default.extname(componentPath), '');
|
|
1198
|
+
if (this.options.isBuildPlugin) {
|
|
1199
|
+
componentName = componentName.replace(/plugin\//, '');
|
|
1200
|
+
}
|
|
1176
1201
|
}
|
|
1177
1202
|
return componentName.replace(/^(\/|\\)/, '');
|
|
1178
1203
|
}
|
|
1179
|
-
getIsBuildPluginPath(filePath, isBuildPlugin) {
|
|
1180
|
-
return isBuildPlugin ? `plugin/${filePath}` : filePath;
|
|
1181
|
-
}
|
|
1182
1204
|
/**
|
|
1183
1205
|
* 根据 app、页面、组件的路径获取对应的 config 配置文件的路径
|
|
1184
1206
|
* @returns config 的路径
|
|
@@ -1247,10 +1269,10 @@ class TaroMiniPlugin {
|
|
|
1247
1269
|
this.independentPackages.forEach((_, name) => { independentPackageNames.push(name); });
|
|
1248
1270
|
Object.keys(assets).forEach(assetName => {
|
|
1249
1271
|
const fileName = path_1.default.basename(assetName, path_1.default.extname(assetName));
|
|
1250
|
-
if ((helper_1.REG_STYLE.test(assetName) || REG_STYLE_EXT.test(assetName))
|
|
1251
|
-
|
|
1272
|
+
if ((helper_1.REG_STYLE.test(assetName) || REG_STYLE_EXT.test(assetName)) &&
|
|
1273
|
+
this.options.commonChunks.includes(fileName) &&
|
|
1252
1274
|
// app.wxss 不能引入独立分包中的 common 样式文件
|
|
1253
|
-
|
|
1275
|
+
independentPackageNames.every(name => !assetName.includes(name))) {
|
|
1254
1276
|
commons.add('\n');
|
|
1255
1277
|
commons.add(`@import ${JSON.stringify((0, loader_utils_1.urlToRequest)(assetName))};`);
|
|
1256
1278
|
componentCommons.push(assetName);
|
|
@@ -1278,7 +1300,7 @@ class TaroMiniPlugin {
|
|
|
1278
1300
|
const source = new ConcatSource('');
|
|
1279
1301
|
const originSource = assets[pageStyle];
|
|
1280
1302
|
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`);
|
|
1303
|
+
source.add(`@import ${JSON.stringify((0, loader_utils_1.urlToRequest)(path_1.default.posix.relative(path_1.default.dirname(pageStyle), item)))};\n`);
|
|
1282
1304
|
});
|
|
1283
1305
|
source.add(originSource);
|
|
1284
1306
|
assets[pageStyle] = source;
|
|
@@ -1287,7 +1309,7 @@ class TaroMiniPlugin {
|
|
|
1287
1309
|
if (pageStyle in assets) {
|
|
1288
1310
|
const source = new ConcatSource('');
|
|
1289
1311
|
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
|
|
1312
|
+
source.add(`@import ${JSON.stringify((0, loader_utils_1.urlToRequest)(path_1.default.posix.relative(path_1.default.dirname(pageStyle), 'app' + styleExt)))};\n`);
|
|
1291
1313
|
source.add(originSource);
|
|
1292
1314
|
assets[pageStyle] = source;
|
|
1293
1315
|
}
|