xhs-mp-compiler-cli 1.0.2 → 1.1.0-beta.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.
Files changed (150) hide show
  1. package/dist/bin/xhs-mp-cli-build.js +3 -3
  2. package/dist/bin/xhs-mp-cli-dev.js +9 -31
  3. package/dist/compiler.d.ts +76 -0
  4. package/dist/compiler.js +361 -0
  5. package/dist/compilerCP.js +175 -0
  6. package/dist/config/constant.config.d.ts +7 -0
  7. package/dist/config/constant.config.js +10 -0
  8. package/dist/dev-server/index.d.ts +2 -2
  9. package/dist/dev-server/index.js +7 -5
  10. package/dist/index.d.ts +1 -11
  11. package/dist/index.js +3 -112
  12. package/dist/packs/index.d.ts +14 -0
  13. package/dist/packs/index.js +31 -0
  14. package/dist/packs/mp-pack/index.d.ts +3 -0
  15. package/dist/packs/mp-pack/index.js +32 -0
  16. package/dist/packs/webpack/index.d.ts +3 -0
  17. package/dist/packs/webpack/index.js +92 -0
  18. package/dist/packs/webpack/webpack.d.ts +21 -0
  19. package/dist/packs/webpack/webpack.js +79 -0
  20. package/dist/{webpack-config/presets → presets}/babel.d.ts +3 -3
  21. package/dist/{webpack-config/presets → presets}/babel.js +13 -11
  22. package/dist/presets/common.d.ts +4 -0
  23. package/dist/presets/common.js +46 -0
  24. package/dist/presets/configs/minigame/assets/assetsEntryPlugin.d.ts +10 -0
  25. package/dist/presets/configs/minigame/assets/assetsEntryPlugin.js +46 -0
  26. package/dist/presets/configs/minigame/assets/index.d.ts +3 -0
  27. package/dist/presets/configs/minigame/assets/index.js +65 -0
  28. package/dist/presets/configs/minigame/service/index.d.ts +3 -0
  29. package/dist/presets/configs/minigame/service/index.js +34 -0
  30. package/dist/{webpack-config/presets/service/XhsResolveLimitPlugin.d.ts → presets/configs/minigame/service/resolveLimitPlugin.d.ts} +3 -3
  31. package/dist/presets/configs/minigame/service/resolveLimitPlugin.js +35 -0
  32. package/dist/presets/configs/minigame/service/serviceChunkPlugin.d.ts +9 -0
  33. package/dist/presets/configs/minigame/service/serviceChunkPlugin.js +69 -0
  34. package/dist/{webpack-config/presets/service/ServiceEntryPlugin.d.ts → presets/configs/minigame/service/serviceEntryPlugin.d.ts} +3 -1
  35. package/dist/presets/configs/minigame/service/serviceEntryPlugin.js +32 -0
  36. package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.d.ts +12 -0
  37. package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.js +132 -0
  38. package/dist/presets/configs/miniprogram/assets/index.d.ts +4 -0
  39. package/dist/presets/configs/miniprogram/assets/index.js +47 -0
  40. package/dist/presets/configs/miniprogram/render/component.d.ts +3 -0
  41. package/dist/presets/configs/miniprogram/render/component.js +47 -0
  42. package/dist/presets/configs/miniprogram/render/index.d.ts +5 -0
  43. package/dist/presets/configs/miniprogram/render/index.js +70 -0
  44. package/dist/presets/configs/miniprogram/render/render.d.ts +3 -0
  45. package/dist/presets/configs/miniprogram/render/render.js +49 -0
  46. package/dist/presets/configs/miniprogram/render/renderChunkPlugin.d.ts +8 -0
  47. package/dist/{webpack-config/presets/render/RenderChunkPlugin.js → presets/configs/miniprogram/render/renderChunkPlugin.js} +13 -8
  48. package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.d.ts +15 -0
  49. package/dist/{webpack-config/presets/render/SjsEntryPlugin.js → presets/configs/miniprogram/render/sjsEntryPlugin.js} +24 -21
  50. package/dist/presets/configs/miniprogram/service/index.d.ts +5 -0
  51. package/dist/presets/configs/miniprogram/service/index.js +72 -0
  52. package/dist/presets/configs/miniprogram/service/resolveLimitPlugin.d.ts +8 -0
  53. package/dist/{webpack-config/presets/service/XhsResolveLimitPlugin.js → presets/configs/miniprogram/service/resolveLimitPlugin.js} +11 -10
  54. package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.d.ts +9 -0
  55. package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.js +65 -0
  56. package/dist/presets/index.d.ts +2 -0
  57. package/dist/presets/index.js +95 -0
  58. package/dist/presets/loaders/mg-entry-loader.js +27 -0
  59. package/dist/{webpack-config → presets}/loaders/mini-style-loader.js +13 -10
  60. package/dist/presets/loaders/mp-entry-loader.js +196 -0
  61. package/dist/{webpack-config → presets}/loaders/sjs-loader/index.js +0 -4
  62. package/dist/{webpack-config → presets}/loaders/wxss-loader.js +7 -6
  63. package/dist/presets/plugins/InjectorPlugin.d.ts +7 -0
  64. package/dist/presets/plugins/InjectorPlugin.js +14 -0
  65. package/dist/presets/prod.d.ts +4 -0
  66. package/dist/presets/prod.js +80 -0
  67. package/dist/types/index.d.ts +18 -6
  68. package/dist/utils/common.d.ts +2 -1
  69. package/dist/utils/common.js +7 -6
  70. package/dist/utils/const.d.ts +27 -0
  71. package/dist/utils/const.js +47 -0
  72. package/dist/{webpack-config/lib → utils}/css.js +6 -6
  73. package/dist/utils/getSuffixName.d.ts +3 -0
  74. package/dist/utils/getSuffixName.js +18 -0
  75. package/dist/{webpack-config/loaders/utils.d.ts → utils/loader-utils.d.ts} +2 -0
  76. package/dist/{webpack-config/loaders/utils.js → utils/loader-utils.js} +19 -1
  77. package/dist/utils/projectConfig.d.ts +1 -1
  78. package/dist/utils/projectConfig.js +2 -2
  79. package/dist/{webpack-config/lib → utils}/utils.js +2 -2
  80. package/package.json +10 -9
  81. package/dist/build/index.d.ts +0 -3
  82. package/dist/build/index.js +0 -22
  83. package/dist/globalData/SjsModule.d.ts +0 -32
  84. package/dist/globalData/SjsModule.js +0 -34
  85. package/dist/utils/combineExtJson.d.ts +0 -3
  86. package/dist/utils/combineExtJson.js +0 -74
  87. package/dist/utils/getCssSuffixName.d.ts +0 -1
  88. package/dist/utils/getCssSuffixName.js +0 -9
  89. package/dist/utils/getMlSuffixName.d.ts +0 -1
  90. package/dist/utils/getMlSuffixName.js +0 -6
  91. package/dist/utils/getPrefixName.d.ts +0 -1
  92. package/dist/utils/getPrefixName.js +0 -6
  93. package/dist/utils/transformAppJson.d.ts +0 -16
  94. package/dist/utils/transformAppJson.js +0 -199
  95. package/dist/utils/validateAppJson.d.ts +0 -4
  96. package/dist/utils/validateAppJson.js +0 -111
  97. package/dist/webpack-config/index.d.ts +0 -4
  98. package/dist/webpack-config/index.js +0 -41
  99. package/dist/webpack-config/lib/const.d.ts +0 -13
  100. package/dist/webpack-config/lib/const.js +0 -15
  101. package/dist/webpack-config/loaders/component-entry-loader.js +0 -31
  102. package/dist/webpack-config/loaders/component-entry-requirements-loader.js +0 -24
  103. package/dist/webpack-config/loaders/render-entry-loader.js +0 -50
  104. package/dist/webpack-config/loaders/service-entry-loader.d.ts +0 -1
  105. package/dist/webpack-config/loaders/service-entry-loader.js +0 -51
  106. package/dist/webpack-config/plugins/VueLoaderPlugin.d.ts +0 -19
  107. package/dist/webpack-config/plugins/VueLoaderPlugin.js +0 -205
  108. package/dist/webpack-config/plugins/XhsMpErrorTransformPlugin.d.ts +0 -8
  109. package/dist/webpack-config/plugins/XhsMpErrorTransformPlugin.js +0 -40
  110. package/dist/webpack-config/plugins/XhsMpJsonPlugin.d.ts +0 -36
  111. package/dist/webpack-config/plugins/XhsMpJsonPlugin.js +0 -71
  112. package/dist/webpack-config/presets/common.d.ts +0 -4
  113. package/dist/webpack-config/presets/common.js +0 -40
  114. package/dist/webpack-config/presets/mp/MpEntryPlugin.d.ts +0 -23
  115. package/dist/webpack-config/presets/mp/MpEntryPlugin.js +0 -87
  116. package/dist/webpack-config/presets/mp/index.d.ts +0 -4
  117. package/dist/webpack-config/presets/mp/index.js +0 -48
  118. package/dist/webpack-config/presets/prod.d.ts +0 -4
  119. package/dist/webpack-config/presets/prod.js +0 -83
  120. package/dist/webpack-config/presets/render/ComponentEntryPlugin.d.ts +0 -18
  121. package/dist/webpack-config/presets/render/ComponentEntryPlugin.js +0 -77
  122. package/dist/webpack-config/presets/render/RenderChunkPlugin.d.ts +0 -5
  123. package/dist/webpack-config/presets/render/RenderEntryPlugin.d.ts +0 -14
  124. package/dist/webpack-config/presets/render/RenderEntryPlugin.js +0 -42
  125. package/dist/webpack-config/presets/render/SjsEntryPlugin.d.ts +0 -31
  126. package/dist/webpack-config/presets/render/index.d.ts +0 -4
  127. package/dist/webpack-config/presets/render/index.js +0 -62
  128. package/dist/webpack-config/presets/service/ServiceEntryPlugin.js +0 -36
  129. package/dist/webpack-config/presets/service/XhsMpServiceChunkPlugin.d.ts +0 -6
  130. package/dist/webpack-config/presets/service/XhsMpServiceChunkPlugin.js +0 -46
  131. package/dist/webpack-config/presets/service/XhsV2AssetsPlugin.d.ts +0 -5
  132. package/dist/webpack-config/presets/service/XhsV2AssetsPlugin.js +0 -27
  133. package/dist/webpack-config/presets/service/index.d.ts +0 -4
  134. package/dist/webpack-config/presets/service/index.js +0 -39
  135. /package/dist/{webpack-config/loaders/component-entry-loader.d.ts → compilerCP.d.ts} +0 -0
  136. /package/dist/{webpack-config/loaders/component-entry-requirements-loader.d.ts → presets/loaders/mg-entry-loader.d.ts} +0 -0
  137. /package/dist/{webpack-config → presets}/loaders/mini-style-loader.d.ts +0 -0
  138. /package/dist/{webpack-config/loaders/render-entry-loader.d.ts → presets/loaders/mp-entry-loader.d.ts} +0 -0
  139. /package/dist/{webpack-config → presets}/loaders/sjs-loader/index.d.ts +0 -0
  140. /package/dist/{webpack-config → presets}/loaders/sjs-loader/scope.d.ts +0 -0
  141. /package/dist/{webpack-config → presets}/loaders/sjs-loader/scope.js +0 -0
  142. /package/dist/{webpack-config → presets}/loaders/sjs-loader/tranform.d.ts +0 -0
  143. /package/dist/{webpack-config → presets}/loaders/sjs-loader/tranform.js +0 -0
  144. /package/dist/{webpack-config → presets}/loaders/wxss-loader.d.ts +0 -0
  145. /package/dist/{webpack-config/lib → utils}/css.d.ts +0 -0
  146. /package/dist/{webpack-config/lib → utils}/postcssRpx2Vw.d.ts +0 -0
  147. /package/dist/{webpack-config/lib → utils}/postcssRpx2Vw.js +0 -0
  148. /package/dist/{webpack-config/lib → utils}/tagTransformMap.d.ts +0 -0
  149. /package/dist/{webpack-config/lib → utils}/tagTransformMap.js +0 -0
  150. /package/dist/{webpack-config/lib → utils}/utils.d.ts +0 -0
@@ -1,18 +0,0 @@
1
- import { Compiler } from 'webpack';
2
- interface IRenderEntryPluginOptions {
3
- enableV1?: boolean;
4
- enableV2?: boolean;
5
- }
6
- declare class RenderEntryPlugin {
7
- enableV1?: boolean;
8
- enableV2?: boolean;
9
- entriesCache: Map<string, boolean>;
10
- subPackageRoots: string[];
11
- constructor(options: IRenderEntryPluginOptions);
12
- isFileInMainPkg(filePath: any): boolean;
13
- isFileInSubpackage(filePath: any): boolean;
14
- apply(compiler: Compiler): void;
15
- makeGlobalEntry(compiler: Compiler, filename: string, url: string): void;
16
- makeUmdEntry(compiler: Compiler, filename: string, url: string, libraryName: string): void;
17
- }
18
- export default RenderEntryPlugin;
@@ -1,77 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const webpack_1 = require("webpack");
7
- const XhsMpJsonPlugin_1 = __importDefault(require("../../plugins/XhsMpJsonPlugin"));
8
- class RenderEntryPlugin {
9
- constructor(options) {
10
- const { enableV1, enableV2 } = options;
11
- this.enableV1 = enableV1;
12
- this.enableV2 = enableV2;
13
- this.entriesCache = new Map();
14
- this.subPackageRoots = [];
15
- }
16
- isFileInMainPkg(filePath) {
17
- return this.subPackageRoots.every(root => !filePath.startsWith(`${root}/`));
18
- }
19
- isFileInSubpackage(filePath) {
20
- return this.subPackageRoots.some(root => filePath.startsWith(`${root}/`));
21
- }
22
- apply(compiler) {
23
- new webpack_1.library.EnableLibraryPlugin('global').apply(compiler);
24
- const hooks = XhsMpJsonPlugin_1.default.getHooks();
25
- hooks.collected.tap('RenderEntryPlugin', ({ xhsData }) => {
26
- const { appJSON } = xhsData;
27
- this.subPackageRoots = appJSON.subPackages.map(pkg => pkg.root);
28
- if (this.enableV2) {
29
- new webpack_1.library.EnableLibraryPlugin('global').apply(compiler);
30
- Object.keys(appJSON.componentsMap).forEach(compPath => {
31
- if (this.isFileInMainPkg(compPath)) {
32
- this.makeGlobalEntry(compiler, `v2/${compPath}.js`, `component-entry-requirements-loader?compPath=${compPath}&pkg=main!`);
33
- }
34
- if (this.isFileInSubpackage(compPath)) {
35
- const root = this.subPackageRoots.find(root => compPath.startsWith(`${root}/`));
36
- this.makeGlobalEntry(compiler, `v2/${root}/${compPath}.js`, `component-entry-requirements-loader?compPath=${compPath}&pkg=sub&root=${root}!`);
37
- }
38
- });
39
- }
40
- /**
41
- * 继续构建 v1 的包,向前兼容
42
- */
43
- if (this.enableV1) {
44
- new webpack_1.library.EnableLibraryPlugin('umd').apply(compiler);
45
- // components
46
- this.makeUmdEntry(compiler, 'v1/components.js', 'component-entry-loader?pkg=main!', 'XHS_COMPONENTS');
47
- for (const subPackage of appJSON.subPackages) {
48
- const { root } = subPackage;
49
- // subPackages 的 components
50
- this.makeUmdEntry(compiler, `v1/${root}/components.js`, `component-entry-loader?pkg=sub&root=${root}!`, `XHS_COMPONENTS_${root}`);
51
- }
52
- }
53
- });
54
- }
55
- makeGlobalEntry(compiler, filename, url) {
56
- if (this.entriesCache.get(filename))
57
- return;
58
- const entryOption = webpack_1.EntryOptionPlugin.entryDescriptionToOptions(compiler, filename, {
59
- import: [url],
60
- filename,
61
- });
62
- new webpack_1.EntryPlugin(compiler.context, url, entryOption).apply(compiler);
63
- this.entriesCache.set(filename, true);
64
- }
65
- makeUmdEntry(compiler, filename, url, libraryName) {
66
- if (this.entriesCache.get(filename))
67
- return;
68
- const entryOption = webpack_1.EntryOptionPlugin.entryDescriptionToOptions(compiler, filename, {
69
- import: [url],
70
- filename,
71
- library: { name: libraryName, type: 'umd' },
72
- });
73
- new webpack_1.EntryPlugin(compiler.context, url, entryOption).apply(compiler);
74
- this.entriesCache.set(filename, true);
75
- }
76
- }
77
- exports.default = RenderEntryPlugin;
@@ -1,5 +0,0 @@
1
- import { Compiler } from 'webpack';
2
- declare class RenderChunkPlugin {
3
- apply(compiler: Compiler): void;
4
- }
5
- export default RenderChunkPlugin;
@@ -1,14 +0,0 @@
1
- import { Compiler } from 'webpack';
2
- interface IRenderEntryPluginOptions {
3
- enableV1?: boolean;
4
- enableV2?: boolean;
5
- }
6
- declare class RenderEntryPlugin {
7
- enableV1?: boolean;
8
- enableV2?: boolean;
9
- entriesCache: Map<string, boolean>;
10
- constructor(options: IRenderEntryPluginOptions);
11
- apply(compiler: Compiler): void;
12
- makeEntry(compiler: Compiler, name: string, url: string): void;
13
- }
14
- export default RenderEntryPlugin;
@@ -1,42 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const webpack_1 = require("webpack");
7
- const XhsMpJsonPlugin_1 = __importDefault(require("../../plugins/XhsMpJsonPlugin"));
8
- class RenderEntryPlugin {
9
- constructor(options) {
10
- const { enableV1, enableV2 } = options;
11
- this.enableV1 = enableV1;
12
- this.enableV2 = enableV2;
13
- this.entriesCache = new Map();
14
- }
15
- apply(compiler) {
16
- const hooks = XhsMpJsonPlugin_1.default.getHooks();
17
- hooks.collected.tap('RenderEntryPlugin', ({ xhsData }) => {
18
- const { appJSON } = xhsData;
19
- new webpack_1.library.EnableLibraryPlugin('umd').apply(compiler);
20
- for (const { path } of appJSON.pages) {
21
- this.enableV1 && this.makeEntry(compiler, `v1/${path}`, `render-entry-loader?mode=v1&path=${path}!`);
22
- this.enableV2 && this.makeEntry(compiler, `v2/${path}`, `render-entry-loader?mode=v2&path=${path}!`);
23
- }
24
- for (const subPackage of appJSON.subPackages) {
25
- const { pages } = subPackage;
26
- for (const { path } of pages) {
27
- // subPackages 的 pages
28
- this.enableV1 && this.makeEntry(compiler, `v1/${path}`, `render-entry-loader?mode=v1&path=${path}!`);
29
- this.enableV2 && this.makeEntry(compiler, `v2/${path}`, `render-entry-loader?mode=v2&path=${path}!`);
30
- }
31
- }
32
- });
33
- }
34
- makeEntry(compiler, name, url) {
35
- if (this.entriesCache.get(name))
36
- return;
37
- const entryOption = webpack_1.EntryOptionPlugin.entryDescriptionToOptions(compiler, name, { import: [url] });
38
- new webpack_1.EntryPlugin(compiler.context, url, entryOption).apply(compiler);
39
- this.entriesCache.set(name, true);
40
- }
41
- }
42
- exports.default = RenderEntryPlugin;
@@ -1,31 +0,0 @@
1
- import { Compilation, Compiler } from 'webpack';
2
- /**
3
- * @NOTE 分包中使用 SJS 的规则
4
- *
5
- * - 整包情况下,可以在所有页面中引用整包内的任意SJS模块。
6
- * - 分包情况下:
7
- * - 主包不能引入分包的 SJS 模块。
8
- * - 分包内部可以引用主分包内的SJS模块。
9
- * - 分包A 和 分包B 之间不可以互相引用SJS模块。
10
- * - 独立分包内的SJS模块只能在独立分包内使用,不能跨分包引用。
11
- */
12
- interface IRenderEntryPluginOptions {
13
- enableV1?: boolean;
14
- enableV2?: boolean;
15
- miniprogramDir: string;
16
- }
17
- declare class SjsEntryPlugin {
18
- enableV1?: boolean;
19
- enableV2?: boolean;
20
- entriesCache: Map<string, boolean>;
21
- mainpkgPaths: string[];
22
- subPackagePaths: Map<string, string[]>;
23
- miniprogramDir: string;
24
- subPackageRoots: string[];
25
- constructor(options: IRenderEntryPluginOptions);
26
- isFileInMainPkg(filePath: any): boolean;
27
- isFileInSubpackage(filePath: any): boolean;
28
- apply(compiler: Compiler): void;
29
- makeSjsFileContent(compilation: Compilation, chunkName: string, sjsFiles: string[] | undefined, sjsModuleName: string, pkgRoot?: string): void;
30
- }
31
- export default SjsEntryPlugin;
@@ -1,4 +0,0 @@
1
- import Config from 'webpack-chain';
2
- import { WebpackPresetOptions } from '../../../types';
3
- declare const getBaseConfig: (chain: Config, options: WebpackPresetOptions) => void;
4
- export default getBaseConfig;
@@ -1,62 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const XhsMpJsonPlugin_1 = __importDefault(require("../../plugins/XhsMpJsonPlugin"));
7
- const RenderEntryPlugin_1 = __importDefault(require("./RenderEntryPlugin"));
8
- const ComponentEntryPlugin_1 = __importDefault(require("./ComponentEntryPlugin"));
9
- const css_1 = __importDefault(require("../../lib/css"));
10
- const types_1 = require("../../../types");
11
- const getMlSuffixName_1 = __importDefault(require("../../../utils/getMlSuffixName"));
12
- const getCssSuffixName_1 = __importDefault(require("../../../utils/getCssSuffixName"));
13
- const SjsEntryPlugin_1 = __importDefault(require("./SjsEntryPlugin"));
14
- const RenderChunkPlugin_1 = __importDefault(require("./RenderChunkPlugin"));
15
- const getBaseConfig = (chain, options) => {
16
- const { extJsonPath, env, enableV1, enableV2, enableVDom, mpDir, miniprogramDir } = options;
17
- const isProd = env === types_1.ENV.production;
18
- const mlReg = new RegExp(`.${(0, getMlSuffixName_1.default)()}$`);
19
- const cssReg = new RegExp(`.${(0, getCssSuffixName_1.default)()}$`);
20
- chain.merge({
21
- externals: { vue: 'vue' },
22
- output: {
23
- path: options.distDir,
24
- filename: '[name].render.js',
25
- globalObject: 'globalThis',
26
- uniqueName: 'MpRender',
27
- },
28
- module: {
29
- rule: {
30
- ml: {
31
- test: mlReg,
32
- use: {
33
- 'ml-loader': {
34
- loader: require.resolve('xhs-mp-compiler-ml-loader'),
35
- options: {
36
- removeComentNode: isProd,
37
- vdom: enableVDom,
38
- },
39
- },
40
- },
41
- },
42
- [(0, getCssSuffixName_1.default)()]: {
43
- test: cssReg,
44
- use: (0, css_1.default)(options, [
45
- "mini-style-loader",
46
- 'postcss-loader',
47
- 'wxss-loader',
48
- ].filter(Boolean)),
49
- }
50
- },
51
- },
52
- });
53
- chain.plugin('XhsMpJsonPlugin').use(XhsMpJsonPlugin_1.default, [{ mpDir, miniprogramDir, extJsonPath }]);
54
- // 组件层
55
- chain.plugin('ComponentEntryPlugin').use(ComponentEntryPlugin_1.default, [{ enableV1, enableV2 }]);
56
- // 渲染层
57
- chain.plugin('XhsMpEntryPlugin').use(RenderEntryPlugin_1.default, [{ enableV1, enableV2 }]);
58
- chain.plugin('SjsEntryPlugin').use(SjsEntryPlugin_1.default, [{ miniprogramDir, enableV1, enableV2 }]);
59
- // 公共模块
60
- chain.plugin("RenderChunkPlugin").use(RenderChunkPlugin_1.default);
61
- };
62
- exports.default = getBaseConfig;
@@ -1,36 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const webpack_1 = require("webpack");
7
- const XhsMpJsonPlugin_1 = __importDefault(require("../../plugins/XhsMpJsonPlugin"));
8
- const common_1 = require("../../../utils/common");
9
- class ServiceEntryPlugin {
10
- constructor() {
11
- this.entriesCache = new Map();
12
- }
13
- apply(compiler) {
14
- new webpack_1.library.EnableLibraryPlugin('umd').apply(compiler);
15
- const hooks = XhsMpJsonPlugin_1.default.getHooks();
16
- hooks.collected.tap('ServiceEntryPlugin', ({ xhsData }) => {
17
- const { appJSON } = xhsData;
18
- this.makeUmdEntry(compiler, 'v1/service.js', 'service-entry-loader?pkg=main!', 'XHS_SERVICE');
19
- for (const { root } of appJSON.subPackages) {
20
- this.makeUmdEntry(compiler, (0, common_1.unixJoin)('v1', root, 'service.js'), `service-entry-loader?pkg=sub&root=${root}!`, `XHS_SERVICE_${root}`);
21
- }
22
- });
23
- }
24
- makeUmdEntry(compiler, filename, url, libraryName) {
25
- if (this.entriesCache.get(filename))
26
- return;
27
- const entryOption = webpack_1.EntryOptionPlugin.entryDescriptionToOptions(compiler, filename, {
28
- import: [url],
29
- filename,
30
- library: { name: libraryName, type: 'umd', },
31
- });
32
- new webpack_1.EntryPlugin(compiler.context, url, entryOption).apply(compiler);
33
- this.entriesCache.set(filename, true);
34
- }
35
- }
36
- exports.default = ServiceEntryPlugin;
@@ -1,6 +0,0 @@
1
- import { Compiler } from 'webpack';
2
- declare class XhsMpServiceChunkPlugin {
3
- apply(compiler: Compiler): void;
4
- updateIndependentService(compiler: any, compilation: any, runtimeCode: any): void;
5
- }
6
- export default XhsMpServiceChunkPlugin;
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const webpack_1 = require("webpack");
4
- const webpack_sources_1 = require("webpack-sources");
5
- const common_1 = require("../../../utils/common");
6
- class XhsMpServiceChunkPlugin {
7
- apply(compiler) {
8
- compiler.hooks.compilation.tap('XhsMpServiceChunkPlugin', compilation => {
9
- compilation.hooks.processAssets.tap({
10
- name: 'XhsMpServiceChunkPlugin',
11
- stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
12
- }, () => {
13
- var _a, _b, _c;
14
- const serviceSource = (_a = compilation.getAsset('v1/service.js')) === null || _a === void 0 ? void 0 : _a.source;
15
- let runtimeCode = (_b = compilation.getAsset('runtime.js')) === null || _b === void 0 ? void 0 : _b.source.source();
16
- // 当没有引用相同 js 场景时, commonChunk 将是 undefined
17
- const commonSource = ((_c = compilation.getAsset('service-common.js')) === null || _c === void 0 ? void 0 : _c.source) || '';
18
- runtimeCode = `
19
- if (!globalThis.__XHS_SERVICE_RUNTIME_REGISTERED__) {
20
- globalThis.__XHS_SERVICE_RUNTIME_REGISTERED__ = true;
21
- ${runtimeCode}
22
- }`;
23
- // 独立分包加入 runtimeChunk
24
- if (serviceSource) {
25
- // @ts-ignore 主包加入 runtimeChunk、commonChunk
26
- compilation.updateAsset('v1/service.js', new webpack_sources_1.ConcatSource(runtimeCode, commonSource, serviceSource));
27
- }
28
- this.updateIndependentService(compiler, compilation, runtimeCode);
29
- compilation.deleteAsset('runtime.js');
30
- compilation.deleteAsset('service-common.js');
31
- });
32
- });
33
- }
34
- updateIndependentService(compiler, compilation, runtimeCode) {
35
- var _a;
36
- (_a = compiler.xhsData.appJSON.subPackages) === null || _a === void 0 ? void 0 : _a.filter(sub => sub.independent).map(sub => (0, common_1.unixJoin)('v1', sub.root, 'service.js')).forEach(servicePath => {
37
- var _a;
38
- const independentServiceSource = (_a = compilation.getAsset(servicePath)) === null || _a === void 0 ? void 0 : _a.source;
39
- if (compilation.getAsset(servicePath)) {
40
- // @ts-ignore
41
- compilation.updateAsset(servicePath, new webpack_sources_1.ConcatSource(runtimeCode, independentServiceSource));
42
- }
43
- });
44
- }
45
- }
46
- exports.default = XhsMpServiceChunkPlugin;
@@ -1,5 +0,0 @@
1
- import { Compiler } from "webpack";
2
- declare class XhsV2AssetsPlugin {
3
- apply(compiler: Compiler): void;
4
- }
5
- export default XhsV2AssetsPlugin;
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const webpack_1 = require("webpack");
4
- class XhsV2AssetsPlugin {
5
- apply(compiler) {
6
- compiler.hooks.compilation.tap(XhsV2AssetsPlugin.name, compilation => {
7
- // @ts-ignore
8
- compilation.hooks.processAssets.tap({
9
- name: XhsV2AssetsPlugin.name,
10
- stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_COMPATIBILITY, // see below for more stages
11
- }, (assets) => {
12
- // @ts-ignore
13
- const { appJSON } = compiler.xhsData;
14
- // eslint-disable-next-line no-unneeded-ternary
15
- if (assets['v1/service.js']) {
16
- assets['v2/service.js'] = assets['v1/service.js'];
17
- }
18
- for (const { root } of appJSON.subPackages) {
19
- if (assets[`v1/${root}/service.js`]) {
20
- assets[`v2/${root}/service.js`] = assets[`v1/${root}/service.js`];
21
- }
22
- }
23
- });
24
- });
25
- }
26
- }
27
- exports.default = XhsV2AssetsPlugin;
@@ -1,4 +0,0 @@
1
- import Config from 'webpack-chain';
2
- import { CliConfig } from '../../../types';
3
- declare const presetService: (chain: Config, options: CliConfig) => void;
4
- export default presetService;
@@ -1,39 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const XhsMpJsonPlugin_1 = __importDefault(require("../../plugins/XhsMpJsonPlugin"));
7
- const ServiceEntryPlugin_1 = __importDefault(require("./ServiceEntryPlugin"));
8
- const XhsMpServiceChunkPlugin_1 = __importDefault(require("./XhsMpServiceChunkPlugin"));
9
- const XhsV2AssetsPlugin_1 = __importDefault(require("./XhsV2AssetsPlugin"));
10
- const presetService = (chain, options) => {
11
- const { extJsonPath, enableV2 } = options;
12
- chain.merge({
13
- output: {
14
- path: options.distDir,
15
- globalObject: 'globalThis',
16
- uniqueName: 'MpService',
17
- },
18
- });
19
- chain.plugin('ServiceEntryPlugin').use(ServiceEntryPlugin_1.default);
20
- chain
21
- .plugin('XhsMpJsonPlugin')
22
- .use(XhsMpJsonPlugin_1.default, [
23
- { mpDir: options.mpDir, miniprogramDir: options.miniprogramDir, extJsonPath },
24
- ]);
25
- chain.plugin('XhsMpServiceChunkPlugin').use(XhsMpServiceChunkPlugin_1.default);
26
- if (enableV2) {
27
- chain.plugin('XhsMpVersionStage2AssetsPlugin').use(XhsV2AssetsPlugin_1.default);
28
- }
29
- chain.optimization
30
- .runtimeChunk({
31
- name: 'runtime',
32
- })
33
- .splitChunks({
34
- chunks: chunk => !chunk.name.startsWith('v0/'),
35
- minSize: 0,
36
- name: 'service-common',
37
- });
38
- };
39
- exports.default = presetService;
File without changes
File without changes