@tarojs/webpack5-runner 3.7.0-canary.6 → 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.
Files changed (52) hide show
  1. package/LICENSE +14 -0
  2. package/dist/index.h5.js +28 -20
  3. package/dist/index.h5.js.map +1 -1
  4. package/dist/index.mini.js +9 -1
  5. package/dist/index.mini.js.map +1 -1
  6. package/dist/loaders/miniCompilerLoader.js +124 -0
  7. package/dist/loaders/miniCompilerLoader.js.map +1 -0
  8. package/dist/plugins/BuildNativePlugin.js +17 -6
  9. package/dist/plugins/BuildNativePlugin.js.map +1 -1
  10. package/dist/plugins/H5Plugin.js +4 -1
  11. package/dist/plugins/H5Plugin.js.map +1 -1
  12. package/dist/plugins/MiniCompileModePlugin.js +317 -0
  13. package/dist/plugins/MiniCompileModePlugin.js.map +1 -0
  14. package/dist/plugins/MiniPlugin.js +100 -76
  15. package/dist/plugins/MiniPlugin.js.map +1 -1
  16. package/dist/plugins/MiniSplitChunksPlugin.js +8 -2
  17. package/dist/plugins/MiniSplitChunksPlugin.js.map +1 -1
  18. package/dist/plugins/TaroComponentsExportsPlugin.js +3 -3
  19. package/dist/plugins/TaroComponentsExportsPlugin.js.map +1 -1
  20. package/dist/plugins/TaroNormalModulesPlugin.js +13 -5
  21. package/dist/plugins/TaroNormalModulesPlugin.js.map +1 -1
  22. package/dist/postcss/postcss.h5.js.map +1 -1
  23. package/dist/postcss/postcss.mini.js +3 -2
  24. package/dist/postcss/postcss.mini.js.map +1 -1
  25. package/dist/utils/webpack.js +7 -1
  26. package/dist/utils/webpack.js.map +1 -1
  27. package/dist/webpack/BaseConfig.js +2 -1
  28. package/dist/webpack/BaseConfig.js.map +1 -1
  29. package/dist/webpack/BuildNativePlugin.js +3 -11
  30. package/dist/webpack/BuildNativePlugin.js.map +1 -1
  31. package/dist/webpack/Combination.js +2 -2
  32. package/dist/webpack/Combination.js.map +1 -1
  33. package/dist/webpack/H5BaseConfig.js +25 -8
  34. package/dist/webpack/H5BaseConfig.js.map +1 -1
  35. package/dist/webpack/H5Combination.js +28 -2
  36. package/dist/webpack/H5Combination.js.map +1 -1
  37. package/dist/webpack/H5WebpackModule.js +9 -22
  38. package/dist/webpack/H5WebpackModule.js.map +1 -1
  39. package/dist/webpack/H5WebpackPlugin.js +7 -2
  40. package/dist/webpack/H5WebpackPlugin.js.map +1 -1
  41. package/dist/webpack/MiniBaseConfig.js +12 -18
  42. package/dist/webpack/MiniBaseConfig.js.map +1 -1
  43. package/dist/webpack/MiniCombination.js +11 -5
  44. package/dist/webpack/MiniCombination.js.map +1 -1
  45. package/dist/webpack/MiniWebpackModule.js +45 -27
  46. package/dist/webpack/MiniWebpackModule.js.map +1 -1
  47. package/dist/webpack/MiniWebpackPlugin.js +10 -8
  48. package/dist/webpack/MiniWebpackPlugin.js.map +1 -1
  49. package/dist/webpack/WebpackModule.js +6 -14
  50. package/dist/webpack/WebpackModule.js.map +1 -1
  51. package/index.js +1 -1
  52. package/package.json +26 -22
@@ -166,7 +166,7 @@ class TaroMiniPlugin {
166
166
  }
167
167
  else if (module.miniType === helper_1.META_TYPE.PAGE) {
168
168
  let isIndependent = false;
169
- this.independentPackages.forEach(pages => {
169
+ this.independentPackages.forEach(({ pages }) => {
170
170
  if (pages.includes(module.resource)) {
171
171
  isIndependent = true;
172
172
  }
@@ -325,6 +325,14 @@ class TaroMiniPlugin {
325
325
  compiler.options.entry = {};
326
326
  return appEntryPath;
327
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
+ }
328
336
  getChangedFiles(compiler) {
329
337
  return compiler.modifiedFiles;
330
338
  }
@@ -333,18 +341,20 @@ class TaroMiniPlugin {
333
341
  * 往 this.dependencies 中添加资源模块
334
342
  */
335
343
  run(compiler) {
336
- if (this.options.isBuildPlugin) {
337
- this.getPluginFiles();
338
- this.getConfigFiles(compiler);
339
- }
340
- else {
341
- this.appConfig = this.getAppConfig();
342
- this.getPages();
343
- this.getPagesConfig();
344
- this.getDarkMode();
345
- this.getConfigFiles(compiler);
346
- this.addEntries();
347
- }
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
+ });
348
358
  }
349
359
  getPluginFiles() {
350
360
  const fileList = new Set();
@@ -367,14 +377,14 @@ class TaroMiniPlugin {
367
377
  Object.keys(pluginConfig).forEach(pluginKey => {
368
378
  if (pluginKey === 'pages') {
369
379
  Object.keys(pluginConfig[pluginKey]).forEach(pageKey => {
370
- if (`plugin/${pluginConfig[pluginKey][pageKey]}` === key) {
380
+ if (`${pluginConfig[pluginKey][pageKey]}` === key) {
371
381
  isPage = true;
372
382
  }
373
383
  });
374
384
  }
375
385
  if (pluginKey === 'publicComponents') {
376
386
  Object.keys(pluginConfig[pluginKey]).forEach(pageKey => {
377
- if (`plugin/${pluginConfig[pluginKey][pageKey]}` === key) {
387
+ if (`${pluginConfig[pluginKey][pageKey]}` === key) {
378
388
  isComponent = true;
379
389
  }
380
390
  });
@@ -404,9 +414,9 @@ class TaroMiniPlugin {
404
414
  }
405
415
  });
406
416
  if (!template.isSupportRecursive) {
407
- this.addEntry(path_1.default.resolve(__dirname, '..', 'template/comp'), this.getIsBuildPluginPath('comp', true), helper_1.META_TYPE.STATIC);
417
+ this.addEntry(path_1.default.resolve(__dirname, '..', 'template/comp'), 'comp', helper_1.META_TYPE.STATIC);
408
418
  }
409
- this.addEntry(path_1.default.resolve(__dirname, '..', 'template/custom-wrapper'), this.getIsBuildPluginPath('custom-wrapper', true), helper_1.META_TYPE.STATIC);
419
+ this.addEntry(path_1.default.resolve(__dirname, '..', 'template/custom-wrapper'), 'custom-wrapper', helper_1.META_TYPE.STATIC);
410
420
  normalFiles.forEach(item => {
411
421
  this.addEntry(item.path, item.name, helper_1.META_TYPE.NORMAL, {
412
422
  library: {
@@ -471,18 +481,24 @@ class TaroMiniPlugin {
471
481
  * @returns app config 配置内容
472
482
  */
473
483
  getAppConfig() {
474
- const appName = path_1.default.basename(this.appEntry).replace(path_1.default.extname(this.appEntry), '');
475
- this.compileFile({
476
- name: appName,
477
- path: this.appEntry,
478
- isNative: false
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;
479
501
  });
480
- const fileConfig = this.filesConfig[this.getConfigFilePath(appName)];
481
- const appConfig = fileConfig ? fileConfig.content || {} : {};
482
- if ((0, helper_1.isEmptyObject)(appConfig)) {
483
- throw new Error('缺少 app 全局配置文件,请检查!');
484
- }
485
- return appConfig;
486
502
  }
487
503
  /**
488
504
  * 根据 app config 的 pages 配置项,收集所有页面信息,
@@ -490,7 +506,6 @@ class TaroMiniPlugin {
490
506
  */
491
507
  getPages() {
492
508
  var _a;
493
- const { newBlended } = this.options;
494
509
  if ((0, helper_1.isEmptyObject)(this.appConfig)) {
495
510
  throw new Error('缺少 app 全局配置文件,请检查!');
496
511
  }
@@ -501,7 +516,7 @@ class TaroMiniPlugin {
501
516
  if (!this.isWatch && ((_a = this.options.logger) === null || _a === void 0 ? void 0 : _a.quiet) === false) {
502
517
  (0, helper_1.printLog)("compile" /* processTypeEnum.COMPILE */, '发现入口', this.getShowPath(this.appEntry));
503
518
  }
504
- const { frameworkExts, combination } = this.options;
519
+ const { newBlended, frameworkExts, combination } = this.options;
505
520
  const { prerender } = combination.config;
506
521
  this.prerenderPages = new Set((0, prerender_1.validatePrerenderPages)(appPages, prerender).map(p => p.path));
507
522
  this.getTabBarFiles(this.appConfig);
@@ -554,7 +569,9 @@ class TaroMiniPlugin {
554
569
  if (!this.isWatch && ((_a = this.options.logger) === null || _a === void 0 ? void 0 : _a.quiet) === false) {
555
570
  (0, helper_1.printLog)("compile" /* processTypeEnum.COMPILE */, '发现页面', this.getShowPath(page.path));
556
571
  }
557
- this.compileFile(page);
572
+ const pagePath = page.path;
573
+ const independentPackage = this.getIndependentPackage(pagePath);
574
+ this.compileFile(page, independentPackage);
558
575
  });
559
576
  }
560
577
  /**
@@ -643,12 +660,12 @@ class TaroMiniPlugin {
643
660
  /**
644
661
  * 读取页面、组件的配置,并递归读取依赖的组件的配置
645
662
  */
646
- compileFile(file) {
663
+ compileFile(file, independentPackage) {
664
+ var _a;
647
665
  const filePath = file.path;
648
666
  const fileConfigPath = file.isNative ? this.replaceExt(filePath, '.json') : this.getConfigFilePath(filePath);
649
667
  const fileConfig = (0, helper_1.readConfig)(fileConfigPath, this.options.combination.config);
650
- const { componentGenerics } = fileConfig;
651
- const usingComponents = fileConfig.usingComponents;
668
+ const { componentGenerics, usingComponents } = fileConfig;
652
669
  if (this.options.isBuildPlugin && componentGenerics) {
653
670
  Object.keys(componentGenerics).forEach(component => {
654
671
  if (componentGenerics[component]) {
@@ -662,7 +679,8 @@ class TaroMiniPlugin {
662
679
  if (usingComponents) {
663
680
  const componentNames = Object.keys(usingComponents);
664
681
  const depComponents = [];
665
- const alias = this.options.combination.config.alias;
682
+ // alias 的值需要从最终的 chain 中拿,避免用户在 webpackChain 中设置的 alias 无法被读取到
683
+ const alias = (_a = this.options.combination.chain.toConfig().resolve) === null || _a === void 0 ? void 0 : _a.alias;
666
684
  for (const compName of componentNames) {
667
685
  let compPath = usingComponents[compName];
668
686
  if ((0, helper_1.isAliasPath)(compPath, alias)) {
@@ -671,9 +689,9 @@ class TaroMiniPlugin {
671
689
  }
672
690
  // 判断是否为第三方依赖的正则,如果 test 为 false 则为第三方依赖
673
691
  const notNpmPkgReg = /^[.\\/]/;
674
- if (!this.options.skipProcessUsingComponents
675
- && !compPath.startsWith('plugin://')
676
- && !notNpmPkgReg.test(compPath)) {
692
+ if (!this.options.skipProcessUsingComponents &&
693
+ !compPath.startsWith('plugin://') &&
694
+ !notNpmPkgReg.test(compPath)) {
677
695
  const tempCompPath = (0, helper_1.getNpmPackageAbsolutePath)(compPath);
678
696
  if (tempCompPath) {
679
697
  compPath = tempCompPath;
@@ -689,6 +707,7 @@ class TaroMiniPlugin {
689
707
  }
690
708
  }
691
709
  depComponents.forEach(item => {
710
+ var _a;
692
711
  const componentPath = (0, helper_1.resolveMainFilePath)(path_1.default.resolve(path_1.default.dirname(file.path), item.path));
693
712
  if (helper_1.fs.existsSync(componentPath) && !Array.from(this.components).some(item => item.path === componentPath)) {
694
713
  const componentName = this.getComponentName(componentPath);
@@ -704,8 +723,10 @@ class TaroMiniPlugin {
704
723
  stylePath: isNative ? this.getStylePath(componentPath) : undefined,
705
724
  templatePath: isNative ? this.getTemplatePath(componentPath) : undefined
706
725
  };
726
+ // 收集独立分包的组件,用于后续单独编译
727
+ (_a = independentPackage === null || independentPackage === void 0 ? void 0 : independentPackage.components) === null || _a === void 0 ? void 0 : _a.push(componentPath);
707
728
  this.components.add(componentObj);
708
- this.compileFile(componentObj);
729
+ this.compileFile(componentObj, independentPackage);
709
730
  }
710
731
  });
711
732
  }
@@ -726,9 +747,10 @@ class TaroMiniPlugin {
726
747
  const root = item.root;
727
748
  const isIndependent = !!item.independent;
728
749
  if (isIndependent) {
729
- this.independentPackages.set(root, []);
750
+ this.independentPackages.set(root, { pages: [], components: [] });
730
751
  }
731
752
  item.pages.forEach(page => {
753
+ var _a;
732
754
  let pageItem = `${root}/${page}`;
733
755
  pageItem = pageItem.replace(/\/{2,}/g, '/');
734
756
  let hasPageIn = false;
@@ -742,7 +764,7 @@ class TaroMiniPlugin {
742
764
  const templatePath = this.getTemplatePath(pagePath);
743
765
  const isNative = this.isNativePageORComponent(templatePath);
744
766
  if (isIndependent) {
745
- const independentPages = this.independentPackages.get(root);
767
+ const independentPages = (_a = this.independentPackages.get(root)) === null || _a === void 0 ? void 0 : _a.pages;
746
768
  independentPages === null || independentPages === void 0 ? void 0 : independentPages.push(pagePath);
747
769
  }
748
770
  this.pages.add({
@@ -776,7 +798,7 @@ class TaroMiniPlugin {
776
798
  const SplitChunksPlugin = require('webpack/lib/optimize/SplitChunksPlugin');
777
799
  const RuntimeChunkPlugin = require('webpack/lib/optimize/RuntimeChunkPlugin');
778
800
  const MiniCssExtractPlugin = require('mini-css-extract-plugin');
779
- independentPackages.forEach((pages, name) => {
801
+ independentPackages.forEach(({ pages, components }, name) => {
780
802
  const childCompiler = compilation.createChildCompiler(PLUGIN_NAME, {
781
803
  path: `${compiler.options.output.path}/${name}`,
782
804
  chunkLoadingGlobal: `subpackage_${name}`
@@ -830,6 +852,13 @@ class TaroMiniPlugin {
830
852
  });
831
853
  dependencies.delete(pagePath);
832
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
+ });
833
862
  new TaroLoadChunksPlugin_1.default({
834
863
  commonChunks: [`${name}/runtime`, `${name}/vendors`, `${name}/common`],
835
864
  isBuildPlugin: false,
@@ -924,8 +953,8 @@ class TaroMiniPlugin {
924
953
  /** 生成小程序独立分包的相关文件 */
925
954
  generateIndependentMiniFiles(compilation, compiler) {
926
955
  return __awaiter(this, void 0, void 0, function* () {
927
- const { template, isBuildPlugin, sourceDir } = this.options;
928
- const baseTemplateName = this.getIsBuildPluginPath('base', isBuildPlugin);
956
+ const { template, sourceDir } = this.options;
957
+ const baseTemplateName = 'base';
929
958
  const isUsingCustomWrapper = component_1.componentConfig.thirdPartyComponents.has('custom-wrapper');
930
959
  // @ts-ignore
931
960
  const childName = compilation.__name;
@@ -953,14 +982,14 @@ class TaroMiniPlugin {
953
982
  }
954
983
  });
955
984
  this.generateTemplateFile(compilation, compiler, `${name}/${customWrapperName}`, template.buildCustomComponentTemplate, this.options.fileType.templ);
956
- this.generateXSFile(compilation, compiler, `${name}/utils`, isBuildPlugin);
985
+ this.generateXSFile(compilation, compiler, `${name}/utils`);
957
986
  });
958
987
  this.pages.forEach(page => {
959
988
  let importBaseTemplatePath = (0, helper_1.promoteRelativePath)(path_1.default.relative(page.path, path_1.default.join(sourceDir, this.getTemplatePath(baseTemplateName))));
960
989
  const config = this.filesConfig[this.getConfigFilePath(page.name)];
961
990
  let isIndependent = false;
962
991
  let independentName = '';
963
- this.independentPackages.forEach((pages, name) => {
992
+ this.independentPackages.forEach(({ pages }, name) => {
964
993
  // independentPackages 是包含了所有 ChildCompiler 的资源,如果不是当前 ChildCompiler 的资源不做处理
965
994
  if (pages.includes(page.path) && name === childName) {
966
995
  isIndependent = true;
@@ -975,8 +1004,8 @@ class TaroMiniPlugin {
975
1004
  this.generateTemplateFile(compilation, compiler, page.path, template.buildPageTemplate, importBaseTemplatePath, config);
976
1005
  }
977
1006
  if (config) {
978
- const importBaseCompPath = (0, helper_1.promoteRelativePath)(path_1.default.relative(page.path, path_1.default.join(sourceDir, independentName, this.getTargetFilePath(this.getIsBuildPluginPath(baseCompName, isBuildPlugin), ''))));
979
- const importCustomWrapperPath = (0, helper_1.promoteRelativePath)(path_1.default.relative(page.path, path_1.default.join(sourceDir, independentName, this.getTargetFilePath(this.getIsBuildPluginPath(customWrapperName, isBuildPlugin), ''))));
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, ''))));
980
1009
  config.content.usingComponents = Object.assign({}, config.content.usingComponents);
981
1010
  if (isUsingCustomWrapper) {
982
1011
  config.content.usingComponents[customWrapperName] = importCustomWrapperPath;
@@ -995,7 +1024,7 @@ class TaroMiniPlugin {
995
1024
  const { RawSource } = compiler.webpack.sources;
996
1025
  const { template, combination, isBuildPlugin, sourceDir } = this.options;
997
1026
  const { modifyMiniConfigs } = combination.config;
998
- const baseTemplateName = this.getIsBuildPluginPath('base', isBuildPlugin);
1027
+ const baseTemplateName = 'base';
999
1028
  const isUsingCustomWrapper = component_1.componentConfig.thirdPartyComponents.has('custom-wrapper');
1000
1029
  /**
1001
1030
  * 与原生小程序混写时解析模板与样式
@@ -1018,7 +1047,7 @@ class TaroMiniPlugin {
1018
1047
  }
1019
1048
  if (!template.isSupportRecursive) {
1020
1049
  // 如微信、QQ 不支持递归模版的小程序,需要使用自定义组件协助递归
1021
- this.generateTemplateFile(compilation, compiler, this.getIsBuildPluginPath(baseCompName, isBuildPlugin), template.buildBaseComponentTemplate, this.options.fileType.templ);
1050
+ this.generateTemplateFile(compilation, compiler, baseCompName, template.buildBaseComponentTemplate, this.options.fileType.templ);
1022
1051
  const baseCompConfig = {
1023
1052
  component: true,
1024
1053
  usingComponents: {
@@ -1027,19 +1056,20 @@ class TaroMiniPlugin {
1027
1056
  };
1028
1057
  if (isUsingCustomWrapper) {
1029
1058
  baseCompConfig.usingComponents[customWrapperName] = `./${customWrapperName}`;
1030
- this.generateConfigFile(compilation, compiler, this.getIsBuildPluginPath(customWrapperName, isBuildPlugin), {
1059
+ this.generateConfigFile(compilation, compiler, customWrapperName, {
1031
1060
  component: true,
1061
+ styleIsolation: 'apply-shared',
1032
1062
  usingComponents: {
1033
1063
  [baseCompName]: `./${baseCompName}`,
1034
1064
  [customWrapperName]: `./${customWrapperName}`
1035
1065
  }
1036
1066
  });
1037
1067
  }
1038
- this.generateConfigFile(compilation, compiler, this.getIsBuildPluginPath(baseCompName, isBuildPlugin), baseCompConfig);
1068
+ this.generateConfigFile(compilation, compiler, baseCompName, baseCompConfig);
1039
1069
  }
1040
1070
  else {
1041
1071
  if (isUsingCustomWrapper) {
1042
- this.generateConfigFile(compilation, compiler, this.getIsBuildPluginPath(customWrapperName, isBuildPlugin), {
1072
+ this.generateConfigFile(compilation, compiler, customWrapperName, {
1043
1073
  component: true,
1044
1074
  usingComponents: {
1045
1075
  [customWrapperName]: `./${customWrapperName}`
@@ -1048,10 +1078,10 @@ class TaroMiniPlugin {
1048
1078
  }
1049
1079
  }
1050
1080
  this.generateTemplateFile(compilation, compiler, baseTemplateName, template.buildTemplate, component_1.componentConfig);
1051
- isUsingCustomWrapper && this.generateTemplateFile(compilation, compiler, this.getIsBuildPluginPath(customWrapperName, isBuildPlugin), template.buildCustomComponentTemplate, this.options.fileType.templ);
1052
- this.generateXSFile(compilation, compiler, 'utils', isBuildPlugin);
1081
+ isUsingCustomWrapper && this.generateTemplateFile(compilation, compiler, customWrapperName, template.buildCustomComponentTemplate, this.options.fileType.templ);
1082
+ this.generateXSFile(compilation, compiler, 'utils');
1053
1083
  this.components.forEach(component => {
1054
- 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))));
1055
1085
  const config = this.filesConfig[this.getConfigFilePath(component.name)];
1056
1086
  if (config) {
1057
1087
  this.generateConfigFile(compilation, compiler, component.path, config.content);
@@ -1061,15 +1091,10 @@ class TaroMiniPlugin {
1061
1091
  }
1062
1092
  });
1063
1093
  this.pages.forEach(page => {
1064
- 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))));
1065
1095
  const config = this.filesConfig[this.getConfigFilePath(page.name)];
1066
- let isIndependent = false;
1067
1096
  // pages 里面会混合独立分包的,在这里需要过滤一下,避免重复生成 assets
1068
- this.independentPackages.forEach(pages => {
1069
- if (pages.includes(page.path)) {
1070
- isIndependent = true;
1071
- }
1072
- });
1097
+ const isIndependent = !!this.getIndependentPackage(page.path);
1073
1098
  if (isIndependent)
1074
1099
  return;
1075
1100
  // 生成页面模板需要在生成页面配置之前,因为会依赖到页面配置的部分内容
@@ -1077,8 +1102,8 @@ class TaroMiniPlugin {
1077
1102
  this.generateTemplateFile(compilation, compiler, page.path, template.buildPageTemplate, importBaseTemplatePath, config);
1078
1103
  }
1079
1104
  if (config) {
1080
- const importBaseCompPath = (0, helper_1.promoteRelativePath)(path_1.default.relative(page.path, path_1.default.join(sourceDir, this.getTargetFilePath(this.getIsBuildPluginPath(baseCompName, isBuildPlugin), ''))));
1081
- const importCustomWrapperPath = (0, helper_1.promoteRelativePath)(path_1.default.relative(page.path, path_1.default.join(sourceDir, this.getTargetFilePath(this.getIsBuildPluginPath(customWrapperName, isBuildPlugin), ''))));
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, ''))));
1082
1107
  config.content.usingComponents = Object.assign({}, config.content.usingComponents);
1083
1108
  if (isUsingCustomWrapper) {
1084
1109
  config.content.usingComponents[customWrapperName] = importCustomWrapperPath;
@@ -1099,8 +1124,7 @@ class TaroMiniPlugin {
1099
1124
  if (helper_1.fs.existsSync(pluginJSONPath)) {
1100
1125
  const pluginJSON = helper_1.fs.readJSONSync(pluginJSONPath);
1101
1126
  this.modifyPluginJSON(pluginJSON);
1102
- const relativePath = pluginJSONPath.replace(sourceDir, '').replace(/\\/g, '/');
1103
- compilation.assets[relativePath] = new RawSource(JSON.stringify(pluginJSON));
1127
+ compilation.assets['plugin.json'] = new RawSource(JSON.stringify(pluginJSON));
1104
1128
  }
1105
1129
  }
1106
1130
  });
@@ -1151,7 +1175,7 @@ class TaroMiniPlugin {
1151
1175
  }
1152
1176
  compilation.assets[fileTemplName] = new RawSource(templStr);
1153
1177
  }
1154
- generateXSFile(compilation, compiler, xsPath, isBuildPlugin) {
1178
+ generateXSFile(compilation, compiler, xsPath) {
1155
1179
  const { RawSource } = compiler.webpack.sources;
1156
1180
  const ext = this.options.fileType.xs;
1157
1181
  const isSupportXS = this.options.template.supportXS;
@@ -1160,7 +1184,7 @@ class TaroMiniPlugin {
1160
1184
  }
1161
1185
  const xs = this.options.template.buildXScript();
1162
1186
  const fileXsName = this.getTargetFilePath(xsPath, ext);
1163
- const filePath = this.getIsBuildPluginPath(fileXsName, isBuildPlugin);
1187
+ const filePath = fileXsName;
1164
1188
  compilation.assets[filePath] = new RawSource(xs);
1165
1189
  }
1166
1190
  getComponentName(componentPath) {
@@ -1171,12 +1195,12 @@ class TaroMiniPlugin {
1171
1195
  }
1172
1196
  else {
1173
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
+ }
1174
1201
  }
1175
1202
  return componentName.replace(/^(\/|\\)/, '');
1176
1203
  }
1177
- getIsBuildPluginPath(filePath, isBuildPlugin) {
1178
- return isBuildPlugin ? `plugin/${filePath}` : filePath;
1179
- }
1180
1204
  /**
1181
1205
  * 根据 app、页面、组件的路径获取对应的 config 配置文件的路径
1182
1206
  * @returns config 的路径
@@ -1245,10 +1269,10 @@ class TaroMiniPlugin {
1245
1269
  this.independentPackages.forEach((_, name) => { independentPackageNames.push(name); });
1246
1270
  Object.keys(assets).forEach(assetName => {
1247
1271
  const fileName = path_1.default.basename(assetName, path_1.default.extname(assetName));
1248
- if ((helper_1.REG_STYLE.test(assetName) || REG_STYLE_EXT.test(assetName))
1249
- && this.options.commonChunks.includes(fileName)
1272
+ if ((helper_1.REG_STYLE.test(assetName) || REG_STYLE_EXT.test(assetName)) &&
1273
+ this.options.commonChunks.includes(fileName) &&
1250
1274
  // app.wxss 不能引入独立分包中的 common 样式文件
1251
- && independentPackageNames.every(name => !assetName.includes(name))) {
1275
+ independentPackageNames.every(name => !assetName.includes(name))) {
1252
1276
  commons.add('\n');
1253
1277
  commons.add(`@import ${JSON.stringify((0, loader_utils_1.urlToRequest)(assetName))};`);
1254
1278
  componentCommons.push(assetName);
@@ -1285,7 +1309,7 @@ class TaroMiniPlugin {
1285
1309
  if (pageStyle in assets) {
1286
1310
  const source = new ConcatSource('');
1287
1311
  const originSource = assets[pageStyle];
1288
- source.add(`@import ${JSON.stringify((0, loader_utils_1.urlToRequest)(path_1.default.posix.relative(path_1.default.dirname(pageStyle), 'app.wxss')))};\n`);
1312
+ source.add(`@import ${JSON.stringify((0, loader_utils_1.urlToRequest)(path_1.default.posix.relative(path_1.default.dirname(pageStyle), 'app' + styleExt)))};\n`);
1289
1313
  source.add(originSource);
1290
1314
  assets[pageStyle] = source;
1291
1315
  }