xhs-mp-compiler-cli 1.1.1 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/package.json +11 -5
  2. package/dist/bin/xhs-mp-cli-build.d.ts +0 -2
  3. package/dist/bin/xhs-mp-cli-build.js +0 -40
  4. package/dist/bin/xhs-mp-cli-dev.d.ts +0 -2
  5. package/dist/bin/xhs-mp-cli-dev.js +0 -59
  6. package/dist/bin/xhs-mp-cli.d.ts +0 -2
  7. package/dist/bin/xhs-mp-cli.js +0 -16
  8. package/dist/compiler.d.ts +0 -76
  9. package/dist/compiler.js +0 -361
  10. package/dist/compilerCP.d.ts +0 -1
  11. package/dist/compilerCP.js +0 -175
  12. package/dist/config/constant.config.d.ts +0 -7
  13. package/dist/config/constant.config.js +0 -10
  14. package/dist/dev-server/index.d.ts +0 -3
  15. package/dist/dev-server/index.js +0 -64
  16. package/dist/dev-server/lib/ensurePort.d.ts +0 -2
  17. package/dist/dev-server/lib/ensurePort.js +0 -32
  18. package/dist/dev-server/lib/openBrowser.d.ts +0 -2
  19. package/dist/dev-server/lib/openBrowser.js +0 -23
  20. package/dist/dev-server/lib/openChrome.applescript +0 -78
  21. package/dist/index.d.ts +0 -1
  22. package/dist/index.js +0 -5
  23. package/dist/packs/index.d.ts +0 -14
  24. package/dist/packs/index.js +0 -31
  25. package/dist/packs/mp-pack/index.d.ts +0 -3
  26. package/dist/packs/mp-pack/index.js +0 -32
  27. package/dist/packs/webpack/index.d.ts +0 -3
  28. package/dist/packs/webpack/index.js +0 -92
  29. package/dist/packs/webpack/webpack.d.ts +0 -21
  30. package/dist/packs/webpack/webpack.js +0 -79
  31. package/dist/presets/babel.d.ts +0 -8
  32. package/dist/presets/babel.js +0 -59
  33. package/dist/presets/common.d.ts +0 -4
  34. package/dist/presets/common.js +0 -46
  35. package/dist/presets/configs/minigame/assets/assetsEntryPlugin.d.ts +0 -10
  36. package/dist/presets/configs/minigame/assets/assetsEntryPlugin.js +0 -46
  37. package/dist/presets/configs/minigame/assets/index.d.ts +0 -2
  38. package/dist/presets/configs/minigame/assets/index.js +0 -65
  39. package/dist/presets/configs/minigame/service/index.d.ts +0 -3
  40. package/dist/presets/configs/minigame/service/index.js +0 -34
  41. package/dist/presets/configs/minigame/service/resolveLimitPlugin.d.ts +0 -8
  42. package/dist/presets/configs/minigame/service/resolveLimitPlugin.js +0 -35
  43. package/dist/presets/configs/minigame/service/serviceChunkPlugin.d.ts +0 -9
  44. package/dist/presets/configs/minigame/service/serviceChunkPlugin.js +0 -69
  45. package/dist/presets/configs/minigame/service/serviceEntryPlugin.d.ts +0 -10
  46. package/dist/presets/configs/minigame/service/serviceEntryPlugin.js +0 -32
  47. package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.d.ts +0 -12
  48. package/dist/presets/configs/miniprogram/assets/assetsEntryPlugin.js +0 -132
  49. package/dist/presets/configs/miniprogram/assets/index.d.ts +0 -4
  50. package/dist/presets/configs/miniprogram/assets/index.js +0 -47
  51. package/dist/presets/configs/miniprogram/render/component.d.ts +0 -3
  52. package/dist/presets/configs/miniprogram/render/component.js +0 -47
  53. package/dist/presets/configs/miniprogram/render/index.d.ts +0 -5
  54. package/dist/presets/configs/miniprogram/render/index.js +0 -70
  55. package/dist/presets/configs/miniprogram/render/render.d.ts +0 -3
  56. package/dist/presets/configs/miniprogram/render/render.js +0 -49
  57. package/dist/presets/configs/miniprogram/render/renderChunkPlugin.d.ts +0 -8
  58. package/dist/presets/configs/miniprogram/render/renderChunkPlugin.js +0 -55
  59. package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.d.ts +0 -15
  60. package/dist/presets/configs/miniprogram/render/sjsEntryPlugin.js +0 -163
  61. package/dist/presets/configs/miniprogram/service/index.d.ts +0 -5
  62. package/dist/presets/configs/miniprogram/service/index.js +0 -72
  63. package/dist/presets/configs/miniprogram/service/resolveLimitPlugin.d.ts +0 -8
  64. package/dist/presets/configs/miniprogram/service/resolveLimitPlugin.js +0 -66
  65. package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.d.ts +0 -9
  66. package/dist/presets/configs/miniprogram/service/serviceChunkPlugin.js +0 -65
  67. package/dist/presets/index.d.ts +0 -2
  68. package/dist/presets/index.js +0 -95
  69. package/dist/presets/loaders/mg-entry-loader.d.ts +0 -1
  70. package/dist/presets/loaders/mg-entry-loader.js +0 -27
  71. package/dist/presets/loaders/mini-style-loader.d.ts +0 -1
  72. package/dist/presets/loaders/mini-style-loader.js +0 -72
  73. package/dist/presets/loaders/mp-entry-loader.d.ts +0 -1
  74. package/dist/presets/loaders/mp-entry-loader.js +0 -196
  75. package/dist/presets/loaders/sjs-loader/index.d.ts +0 -12
  76. package/dist/presets/loaders/sjs-loader/index.js +0 -605
  77. package/dist/presets/loaders/sjs-loader/scope.d.ts +0 -36
  78. package/dist/presets/loaders/sjs-loader/scope.js +0 -122
  79. package/dist/presets/loaders/sjs-loader/tranform.d.ts +0 -2
  80. package/dist/presets/loaders/sjs-loader/tranform.js +0 -31
  81. package/dist/presets/loaders/wxss-loader.d.ts +0 -1
  82. package/dist/presets/loaders/wxss-loader.js +0 -77
  83. package/dist/presets/plugins/InjectorPlugin.d.ts +0 -7
  84. package/dist/presets/plugins/InjectorPlugin.js +0 -14
  85. package/dist/presets/prod.d.ts +0 -4
  86. package/dist/presets/prod.js +0 -80
  87. package/dist/types/index.d.ts +0 -118
  88. package/dist/types/index.js +0 -13
  89. package/dist/utils/asyncWebpack.d.ts +0 -3
  90. package/dist/utils/asyncWebpack.js +0 -38
  91. package/dist/utils/common.d.ts +0 -8
  92. package/dist/utils/common.js +0 -36
  93. package/dist/utils/const.d.ts +0 -27
  94. package/dist/utils/const.js +0 -47
  95. package/dist/utils/css.d.ts +0 -2
  96. package/dist/utils/css.js +0 -41
  97. package/dist/utils/depenedHelper.d.ts +0 -31
  98. package/dist/utils/depenedHelper.js +0 -89
  99. package/dist/utils/getSuffixName.d.ts +0 -3
  100. package/dist/utils/getSuffixName.js +0 -18
  101. package/dist/utils/loader-utils.d.ts +0 -15
  102. package/dist/utils/loader-utils.js +0 -59
  103. package/dist/utils/postcssRpx2Vw.d.ts +0 -12
  104. package/dist/utils/postcssRpx2Vw.js +0 -35
  105. package/dist/utils/projectConfig.d.ts +0 -1
  106. package/dist/utils/projectConfig.js +0 -20
  107. package/dist/utils/tagTransformMap.d.ts +0 -35
  108. package/dist/utils/tagTransformMap.js +0 -38
  109. package/dist/utils/utils.d.ts +0 -5
  110. package/dist/utils/utils.js +0 -37
@@ -1,132 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const packs_1 = require("../../../../packs");
16
- const const_1 = __importDefault(require("../../../../utils/const"));
17
- class XhsAssetsPlugin {
18
- constructor(options) {
19
- this.options = options;
20
- this.copyPatterns = new packs_1.CopyPatterns();
21
- }
22
- apply(compiler) {
23
- compiler.hooks.compilation.tap('XhsMpAssetsPlugin', compilation => {
24
- const { project, packSetting } = this.options;
25
- const { appJSON, legacyAppJSON } = project;
26
- const usingPackageType = packSetting.usingPackageType;
27
- // app.json
28
- if (compilation) {
29
- this.emitAppJson(compilation, JSON.parse(JSON.stringify(appJSON)));
30
- // 兼容服务端,始终创建 v0/app.json
31
- this.emitLegacyAppJSON(compilation, legacyAppJSON);
32
- }
33
- // app.css 复用
34
- compilation.hooks.processAssets.tap({
35
- name: 'XhsMpAssetsCommonPlugin',
36
- stage: packs_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
37
- }, assets => {
38
- // 删除因为 entry 是 app.(wxss|css) 而产生的的 js 文件
39
- for (const key of Object.keys(assets)) {
40
- if (key === `${usingPackageType}/${const_1.default.ENTRY_CSS_NAME}.js` ||
41
- key === `${usingPackageType}/${const_1.default.ENTRY_CSS_NAME}.js.map`) {
42
- Reflect.deleteProperty(assets, key);
43
- }
44
- }
45
- // 复用app.css,copy v2到v1
46
- if (packSetting.usingPackageType === 'v2' && packSetting.enableV1) {
47
- if (assets[`${usingPackageType}/app.css`]) {
48
- assets['v1/app.css'] = assets[`${usingPackageType}/app.css`];
49
- }
50
- }
51
- });
52
- // 图片等资源
53
- const cache = compilation.getCache('CopyWebpackPlugin');
54
- const logger = compilation.getLogger('XhsMpAssetsCopyPlugin');
55
- compilation.hooks.processAssets.tapAsync({
56
- name: 'XhsMpAssetsCopyPlugin',
57
- stage: packs_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
58
- }, (assets, callback) => __awaiter(this, void 0, void 0, function* () {
59
- const patterns = [];
60
- if (packSetting.enableV2) {
61
- patterns.push({
62
- noErrorOnMissing: true,
63
- from: `**/*.{${const_1.default.ASSETS_EXTS}}`,
64
- to: 'v2',
65
- context: project.projectMiniprogramPath,
66
- globOptions: { gitignore: true }
67
- });
68
- }
69
- if (packSetting.enableV1) {
70
- patterns.push({
71
- noErrorOnMissing: true,
72
- from: `**/*.{${const_1.default.ASSETS_EXTS}}`,
73
- to: 'v1',
74
- context: project.projectMiniprogramPath,
75
- globOptions: { gitignore: true }
76
- });
77
- }
78
- yield this.copyPatterns.copy({
79
- compiler,
80
- compilation,
81
- cache,
82
- logger,
83
- patterns
84
- });
85
- callback();
86
- }));
87
- });
88
- }
89
- emitAppJson(compilation, appJSON) {
90
- const { project, packSetting } = this.options;
91
- const { compilePkgs = [const_1.default.MAIN_PKG] } = packSetting;
92
- // const { mainPkg, subPkgs } = packSetting.getCompilePkgsForEntries()
93
- // 先删除,用户配置的默认不生效
94
- Reflect.deleteProperty(appJSON, 'lazyCodeLoading');
95
- if (packSetting.enableVDom) {
96
- appJSON.xhsVersionStrategy.enableVDom = true;
97
- appJSON.usingFramework = '2.0';
98
- }
99
- if (packSetting.enableV2) {
100
- appJSON.xhsVersionStrategy.lazyCodeLoading = true;
101
- appJSON.lazyCodeLoading = 'requiredComponents';
102
- }
103
- const appJsonSource = new packs_1.RawSource(JSON.stringify(appJSON));
104
- // app.json合并了普通分包的json内容,每次都emit
105
- if (packSetting.enableV2) {
106
- this.emitJson(compilation, 'v2/app.json', appJsonSource);
107
- }
108
- if (packSetting.enableV1) {
109
- this.emitJson(compilation, 'v1/app.json', appJsonSource);
110
- }
111
- // 独立分包的 app.json
112
- const subPkgs = project.getSubPackages().filter(pkg => compilePkgs.includes(pkg.root));
113
- subPkgs.forEach(subPkg => {
114
- if (subPkg === null || subPkg === void 0 ? void 0 : subPkg.independent) {
115
- if (packSetting.enableV2) {
116
- this.emitJson(compilation, `v2/${subPkg.root}/app.json`, appJsonSource);
117
- }
118
- if (packSetting.enableV1) {
119
- this.emitJson(compilation, `v1/${subPkg.root}/app.json`, appJsonSource);
120
- }
121
- }
122
- });
123
- }
124
- emitLegacyAppJSON(compilation, legacyAppJSON) {
125
- this.emitJson(compilation, 'v0/app.json', new packs_1.RawSource(JSON.stringify(legacyAppJSON)));
126
- }
127
- emitJson(compilation, path, json) {
128
- // @ts-ignore
129
- compilation.emitAsset(path, json);
130
- }
131
- }
132
- exports.default = XhsAssetsPlugin;
@@ -1,4 +0,0 @@
1
- import type { IPresetOptions } from '../../../../types';
2
- declare const getAssetsEntry: (options: IPresetOptions) => () => {};
3
- declare const presetAssets: (chain: any, options: IPresetOptions) => void;
4
- export { getAssetsEntry, presetAssets };
@@ -1,47 +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
- exports.presetAssets = exports.getAssetsEntry = void 0;
7
- const css_1 = __importDefault(require("../../../../utils/css"));
8
- const getSuffixName_1 = require("../../../../utils/getSuffixName");
9
- const assetsEntryPlugin_1 = __importDefault(require("./assetsEntryPlugin"));
10
- const const_1 = __importDefault(require("../../../../utils/const"));
11
- const InjectorPlugin_1 = require("../../../plugins/InjectorPlugin");
12
- const getAssetsEntry = (options) => () => {
13
- const { project, packSetting } = options;
14
- const entry = {};
15
- entry[`${packSetting.usingPackageType}/${const_1.default.ENTRY_CSS_NAME}`] = `${project.projectMiniprogramPath}/app.${(0, getSuffixName_1.getCssSuffixName)()}`;
16
- return entry;
17
- };
18
- exports.getAssetsEntry = getAssetsEntry;
19
- const presetAssets = (chain, options) => {
20
- const { packSetting, project } = options;
21
- const { distDir, enableV1, enableV2 } = packSetting;
22
- const { miniprogramDir } = project;
23
- const cssReg = new RegExp(`.${(0, getSuffixName_1.getCssSuffixName)()}$`);
24
- chain.merge({
25
- output: {
26
- path: distDir
27
- },
28
- // cache: {
29
- // type: 'filesystem',
30
- // cacheDirectory: packSetting.cacheDirectory,
31
- // },
32
- module: {
33
- rule: {
34
- [(0, getSuffixName_1.getCssSuffixName)()]: {
35
- test: cssReg,
36
- use: Object.assign({ 'mini-style-loader': {
37
- loader: require.resolve('../../../loaders/mini-style-loader'),
38
- options: Object.assign(Object.assign({}, options), { independent: true })
39
- } }, (0, css_1.default)(options, ['css-loader', 'postcss-loader', 'wxss-loader']))
40
- }
41
- }
42
- }
43
- });
44
- chain.plugin('InjectorPlugin').use(InjectorPlugin_1.InjectorPlugin, [options]);
45
- chain.plugin('XhsMpAssetsPlugin').use(assetsEntryPlugin_1.default, [options]);
46
- };
47
- exports.presetAssets = presetAssets;
@@ -1,3 +0,0 @@
1
- import { IPresetOptions } from '../../../../types';
2
- declare const getComponentEntry: (options: IPresetOptions) => {};
3
- export { getComponentEntry };
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getComponentEntry = void 0;
4
- const xhs_mp_pack_1 = require("xhs-mp-pack");
5
- const getComponentEntry = (options) => {
6
- const entries = {};
7
- const { packSetting } = options;
8
- // 编译v2
9
- if (packSetting.enableV2) {
10
- appendV2Entry(options, entries);
11
- }
12
- // 构建 v1 的包
13
- if (packSetting.enableV1) {
14
- appendV1Entry(options, entries);
15
- }
16
- return entries;
17
- };
18
- exports.getComponentEntry = getComponentEntry;
19
- const appendV2Entry = (options, entries) => {
20
- const { project, packSetting } = options;
21
- const subPackages = project.getSubPackages();
22
- const subPackageRoots = subPackages.map(pkg => pkg.root);
23
- const componentsMap = project.getComponentsMap();
24
- const { mainPkg, subPkgs } = packSetting.getCompilePkgsForEntries();
25
- Object.keys(componentsMap).forEach(compPath => {
26
- if (mainPkg && project.isFileInMainPkg(compPath)) {
27
- entries[`v2/${compPath}`] = `mp-entry-loader?type=component&mode=v2&compPath=${compPath}&pkg=${xhs_mp_pack_1.CONSTANTS.MAIN_PKG}!`;
28
- }
29
- for (const subPkg of subPkgs) {
30
- if (compPath.startsWith(`${subPkg.root}/`)) {
31
- const root = subPackageRoots.find(root => compPath.startsWith(`${root}/`));
32
- entries[`v2/${root}/${compPath}`] = `mp-entry-loader?type=component&mode=v2&compPath=${compPath}&pkg=${xhs_mp_pack_1.CONSTANTS.SUB_PKG}&root=${root}!`;
33
- }
34
- }
35
- });
36
- };
37
- function appendV1Entry(options, entries) {
38
- const { packSetting } = options;
39
- const { mainPkg, subPkgs } = packSetting.getCompilePkgsForEntries();
40
- if (mainPkg) {
41
- entries['v1/components'] = `mp-entry-loader?type=component&mode=v1&pkg=${xhs_mp_pack_1.CONSTANTS.MAIN_PKG}!`;
42
- }
43
- for (const subPkg of subPkgs) {
44
- const { root } = subPkg;
45
- entries[`v1/${root}/components`] = `mp-entry-loader?type=component&mode=v1&pkg=${xhs_mp_pack_1.CONSTANTS.SUB_PKG}&root=${root}!`;
46
- }
47
- }
@@ -1,5 +0,0 @@
1
- import { Config } from '../../../../packs';
2
- import { IPresetOptions } from '../../../../types';
3
- declare const getRenderEntry: (options: IPresetOptions) => () => {};
4
- declare const presetRender: (chain: Config, options: IPresetOptions) => void;
5
- export { getRenderEntry, presetRender };
@@ -1,70 +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
- exports.presetRender = exports.getRenderEntry = void 0;
7
- const css_1 = __importDefault(require("../../../../utils/css"));
8
- const getSuffixName_1 = require("../../../../utils/getSuffixName");
9
- const sjsEntryPlugin_1 = __importDefault(require("./sjsEntryPlugin"));
10
- const render_1 = require("./render");
11
- const component_1 = require("./component");
12
- const renderChunkPlugin_1 = __importDefault(require("./renderChunkPlugin"));
13
- const types_1 = require("../../../../types");
14
- const InjectorPlugin_1 = require("../../../plugins/InjectorPlugin");
15
- const getRenderEntry = (options) => () => (Object.assign(Object.assign({}, (0, render_1.getRenderEntry)(options)), (0, component_1.getComponentEntry)(options)));
16
- exports.getRenderEntry = getRenderEntry;
17
- const presetRender = (chain, options) => {
18
- const { packSetting } = options;
19
- const { enableVDom, env, distDir } = packSetting;
20
- const mlReg = new RegExp(`.${(0, getSuffixName_1.getMlSuffixName)()}$`);
21
- const cssReg = new RegExp(`.${(0, getSuffixName_1.getCssSuffixName)()}$`);
22
- const isProd = env === types_1.ENV.production;
23
- chain.merge({
24
- externals: { vue: 'vue' },
25
- output: {
26
- path: distDir,
27
- globalObject: 'globalThis',
28
- libraryTarget: 'umd',
29
- uniqueName: 'MpRender',
30
- },
31
- // cache: {
32
- // type: 'filesystem',
33
- // cacheDirectory: packSetting.cacheDirectory,
34
- // },
35
- module: {
36
- rule: {
37
- ml: {
38
- test: mlReg,
39
- use: {
40
- // 'thread-loader': {
41
- // loader: require.resolve('thread-loader'),
42
- // options: {
43
- // workers: require('os').cpus().length,
44
- // },
45
- // },
46
- 'ml-loader': {
47
- loader: require.resolve('xhs-mp-compiler-ml-loader'),
48
- options: {
49
- removeComentNode: isProd,
50
- vdom: enableVDom,
51
- },
52
- },
53
- },
54
- },
55
- [(0, getSuffixName_1.getCssSuffixName)()]: {
56
- test: cssReg,
57
- use: (0, css_1.default)(options, [
58
- "mini-style-loader",
59
- 'postcss-loader',
60
- 'wxss-loader',
61
- ]),
62
- },
63
- },
64
- },
65
- });
66
- chain.plugin('InjectorPlugin').use(InjectorPlugin_1.InjectorPlugin, [options]);
67
- chain.plugin('SjsEntryPlugin').use(sjsEntryPlugin_1.default, [options]);
68
- chain.plugin("RenderChunkPlugin").use(renderChunkPlugin_1.default, [options]);
69
- };
70
- exports.presetRender = presetRender;
@@ -1,3 +0,0 @@
1
- import { IPresetOptions } from '../../../../types';
2
- declare const getRenderEntry: (options: IPresetOptions) => {};
3
- export { getRenderEntry };
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRenderEntry = void 0;
4
- const getSuffixName_1 = require("../../../../utils/getSuffixName");
5
- const xhs_mp_pack_1 = require("xhs-mp-pack");
6
- const getRenderEntry = (options) => {
7
- const entries = {};
8
- const { packSetting } = options;
9
- if (packSetting.enableV2) {
10
- appendV2Entry(options, entries);
11
- }
12
- if (packSetting.enableV1) {
13
- appendV1Entry(options, entries);
14
- }
15
- return entries;
16
- };
17
- exports.getRenderEntry = getRenderEntry;
18
- const appendV2Entry = (options, entries) => {
19
- const { project, packSetting } = options;
20
- const projectMiniprogramPath = project.projectMiniprogramPath;
21
- const { mainPkg, subPkgs } = packSetting.getCompilePkgsForEntries();
22
- if (mainPkg) {
23
- const pages = project.getPages();
24
- for (const { path } of pages) {
25
- entries[`v2/${path}.render`] = `mp-entry-loader?type=render&mode=v2&pkg=${xhs_mp_pack_1.CONSTANTS.MAIN_PKG}!${projectMiniprogramPath}/${path}.${(0, getSuffixName_1.getMlSuffixName)()}`;
26
- }
27
- }
28
- for (const { pages, root } of subPkgs) {
29
- for (const { path } of pages) {
30
- entries[`v2/${path}.render`] = `mp-entry-loader?type=render&mode=v2&pkg=${xhs_mp_pack_1.CONSTANTS.SUB_PKG}&root=${root}!${projectMiniprogramPath}/${path}.${(0, getSuffixName_1.getMlSuffixName)()}`;
31
- }
32
- }
33
- };
34
- const appendV1Entry = (options, entries) => {
35
- const { project, packSetting } = options;
36
- const projectMiniprogramPath = project.projectMiniprogramPath;
37
- const { mainPkg, subPkgs } = packSetting.getCompilePkgsForEntries();
38
- if (mainPkg) {
39
- const pages = project.getPages();
40
- for (const { path } of pages) {
41
- entries[`v1/${path}.render`] = `mp-entry-loader?type=render&mode=v1&pkg=${xhs_mp_pack_1.CONSTANTS.MAIN_PKG}!${projectMiniprogramPath}/${path}.${(0, getSuffixName_1.getMlSuffixName)()}`;
42
- }
43
- }
44
- for (const { pages, root } of subPkgs) {
45
- for (const { path } of pages) {
46
- entries[`v1/${path}.render`] = `mp-entry-loader?type=render&mode=v1&pkg=${xhs_mp_pack_1.CONSTANTS.SUB_PKG}&root=${root}!${projectMiniprogramPath}/${path}.${(0, getSuffixName_1.getMlSuffixName)()}`;
47
- }
48
- }
49
- };
@@ -1,8 +0,0 @@
1
- import { ICompiler } from '../../../../packs';
2
- import { IPresetOptions } from '../../../../types';
3
- declare class RenderChunkPlugin {
4
- options: IPresetOptions;
5
- constructor(options: IPresetOptions);
6
- apply(compiler: ICompiler): void;
7
- }
8
- export default RenderChunkPlugin;
@@ -1,55 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const packs_1 = require("../../../../packs");
4
- const injectCSS = `
5
- globalThis.__XHS_IS_WEBVIEW = (globalThis.localStorage && document && document.querySelectorAll)
6
- globalThis.__XHS_APPEND_CSS = function(cssText){
7
- if (!globalThis.__XHS_IS_WEBVIEW) return;
8
- var headTags = document.getElementsByTagName('head')
9
- var head = document.head || (headTags && headTags[0])
10
- var cssTextNode = document.createTextNode(String(cssText))
11
- var styleNode = document.createElement('style')
12
- styleNode.appendChild(cssTextNode)
13
- head.appendChild(styleNode)
14
- };
15
- `;
16
- // 注入css跟webpack runtime
17
- class RenderChunkPlugin {
18
- constructor(options) {
19
- this.options = options;
20
- }
21
- apply(compiler) {
22
- compiler.hooks.compilation.tap(RenderChunkPlugin.name, compilation => {
23
- compilation.hooks.processAssets.tap({
24
- name: RenderChunkPlugin.name,
25
- stage: packs_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
26
- }, assets => {
27
- var _a, _b;
28
- const { project } = this.options;
29
- // 注入css逻辑
30
- const injectCode = injectCSS;
31
- // @ts-ignore
32
- const appJSON = project.appJSON;
33
- const pathMap = [
34
- (_a = appJSON.pages) === null || _a === void 0 ? void 0 : _a.map(({ path }) => path),
35
- (_b = appJSON.subPackages) === null || _b === void 0 ? void 0 : _b.map(sub => { var _a; return (_a = sub.pages) === null || _a === void 0 ? void 0 : _a.map(({ path }) => path); })
36
- ]
37
- .flat(4)
38
- .filter(Boolean)
39
- .reduce((ac, path) => {
40
- ac[`v1/${path}.render.js`] = true;
41
- ac[`v2/${path}.render.js`] = true;
42
- return ac;
43
- }, {});
44
- // 将runtime 塞到render.js中去
45
- Object.keys(assets).forEach(key => {
46
- if (!pathMap[key])
47
- return;
48
- // @ts-ignore
49
- compilation.updateAsset(key, new packs_1.ConcatSource(injectCode, assets[key]));
50
- });
51
- });
52
- });
53
- }
54
- }
55
- exports.default = RenderChunkPlugin;
@@ -1,15 +0,0 @@
1
- import { Compilation, ICompiler } from '../../../../packs';
2
- import { IPresetOptions } from '../../../../types';
3
- declare class SjsEntryPlugin {
4
- options: IPresetOptions;
5
- entriesCache: Map<string, boolean>;
6
- mainpkgPaths: string[];
7
- subPackagePaths: Map<string, string[]>;
8
- subPackageRoots: string[];
9
- constructor(options: IPresetOptions);
10
- isFileInMainPkg(filePath: any): boolean;
11
- isFileInSubpackage(filePath: any): boolean;
12
- apply(compiler: ICompiler): void;
13
- makeSjsFileContent(compilation: Compilation, chunkName: string, sjsFiles: string[] | undefined, sjsModuleName: string, pkgRoot?: string): void;
14
- }
15
- export default SjsEntryPlugin;
@@ -1,163 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const fs_extra_1 = __importDefault(require("fs-extra"));
30
- const glob_1 = __importDefault(require("glob"));
31
- const path_1 = __importDefault(require("path"));
32
- const packs_1 = require("../../../../packs");
33
- const index_1 = __importStar(require("../../../loaders/sjs-loader/index"));
34
- const common_1 = require("../../../../utils/common");
35
- /**
36
- * @NOTE 分包中使用 SJS 的规则
37
- *
38
- * - 整包情况下,可以在所有页面中引用整包内的任意SJS模块。
39
- * - 分包情况下:
40
- * - 主包不能引入分包的 SJS 模块。
41
- * - 分包内部可以引用主分包内的SJS模块。
42
- * - 分包A 和 分包B 之间不可以互相引用SJS模块。
43
- * - 独立分包内的SJS模块只能在独立分包内使用,不能跨分包引用。
44
- */
45
- function formatSJSPath(i) {
46
- if (/\.(sjs|wxs)$/.test(i)) {
47
- return (0, common_1.toUnixPath)(i);
48
- }
49
- const suffix = ['sjs', 'wxs'].find(n => fs_extra_1.default.existsSync(`${i}.${n}`));
50
- if (!suffix) {
51
- throw new packs_1.WebpackError(`[SJS文件编译错误] ${i}.sjs 不存在`);
52
- }
53
- return (0, common_1.toUnixPath)(suffix ? `${i}.${suffix}` : i);
54
- }
55
- class SjsEntryPlugin {
56
- constructor(options) {
57
- this.options = options;
58
- this.entriesCache = new Map();
59
- this.mainpkgPaths = [];
60
- this.subPackagePaths = new Map();
61
- this.subPackageRoots = [];
62
- }
63
- isFileInMainPkg(filePath) {
64
- return this.subPackageRoots.every(root => !filePath.startsWith(`${root}/`));
65
- }
66
- isFileInSubpackage(filePath) {
67
- return this.subPackageRoots.some(root => filePath.startsWith(`${root}/`));
68
- }
69
- apply(compiler) {
70
- compiler.hooks.watchRun.tap('SjsEntryPlugin', () => {
71
- this.subPackagePaths.clear();
72
- this.mainpkgPaths = [];
73
- });
74
- compiler.hooks.emit.tapAsync('SjsEntryPlugin', (compilation, callback) => {
75
- const { project } = this.options;
76
- const { appJSON, miniprogramDir } = project;
77
- this.subPackageRoots = appJSON.subPackages.map(pkg => pkg.root);
78
- // 默认输出一个空的sjs文件
79
- this.subPackageRoots.forEach(root => {
80
- this.subPackagePaths.has(root) || this.subPackagePaths.set(root, []);
81
- });
82
- const relativePaths = glob_1.default.sync('**/*.sjs', { cwd: miniprogramDir })
83
- .concat(glob_1.default.sync('**/*.wxs', { cwd: miniprogramDir }));
84
- relativePaths.forEach(relativePath => {
85
- var _a;
86
- const sjsAbsPath = (0, common_1.unixJoin)(miniprogramDir, relativePath);
87
- // 如果是主包内的文件
88
- if (this.isFileInMainPkg(relativePath)) {
89
- this.mainpkgPaths.push(sjsAbsPath);
90
- }
91
- // 如果命中了分包内的文件
92
- if (this.isFileInSubpackage(relativePath)) {
93
- const root = this.subPackageRoots.find(root => relativePath.startsWith(`${root}/`));
94
- if (root) {
95
- (_a = this.subPackagePaths.get(root)) === null || _a === void 0 ? void 0 : _a.push(sjsAbsPath);
96
- }
97
- }
98
- });
99
- // 主包
100
- this.makeSjsFileContent(compilation, 'sjs.js', [...this.mainpkgPaths], 'XHS_SJS');
101
- // 分包
102
- Array.from(this.subPackagePaths.keys()).forEach(pkgRoot => {
103
- const paths = this.subPackagePaths.get(pkgRoot);
104
- this.makeSjsFileContent(compilation, `${pkgRoot}/sjs.js`, [...paths], `XHS_SJS_${pkgRoot}`, pkgRoot);
105
- });
106
- callback();
107
- });
108
- }
109
- makeSjsFileContent(compilation, chunkName, sjsFiles = [], sjsModuleName, pkgRoot) {
110
- var _a;
111
- const { project, packSetting } = this.options;
112
- const sjsModules = [];
113
- // 用于去除重复引入
114
- const sjsPathCache = new Set();
115
- /**
116
- * @NOTE
117
- * 在这里校验 sjs 模块引入的路径是否符合规则,分包的规则见上方
118
- */
119
- let sjsPath;
120
- while ((sjsPath = sjsFiles.shift())) {
121
- if (sjsPathCache.has(sjsPath)) {
122
- continue;
123
- }
124
- const sjsAbsPath = formatSJSPath(sjsPath);
125
- const content = fs_extra_1.default.readFileSync(sjsAbsPath, 'utf8');
126
- const result = index_1.default.call(compilation, content, requirePath => {
127
- const realPath = (0, common_1.unixResolve)(path_1.default.dirname(sjsAbsPath), requirePath);
128
- const relativePath = (0, common_1.getShortPath)(project.miniprogramDir, realPath);
129
- /**
130
- * 不是当前分包的 sjs 文件不处理
131
- */
132
- if (pkgRoot && !relativePath.startsWith(pkgRoot)) {
133
- throw new Error(`require(${JSON.stringify(requirePath)}),请检测引入路径是否正确或符合分包规则!`);
134
- }
135
- if (!fs_extra_1.default.existsSync(realPath)) {
136
- throw new Error(`require(${JSON.stringify(requirePath)}) file does not exist`);
137
- }
138
- sjsFiles.push(realPath);
139
- return relativePath;
140
- });
141
- if ((_a = result.errors) === null || _a === void 0 ? void 0 : _a.length) {
142
- throw new packs_1.WebpackError(`[SJS 文件编译错误] ${sjsAbsPath}\n${result.errors.map(i => i.message).join("\n")}`);
143
- }
144
- const moduleName = (0, common_1.getShortPath)(project.miniprogramDir, sjsAbsPath);
145
- // 老版本兼容代码
146
- sjsModules.push(`"${moduleName}": ${JSON.stringify(result.legacyCode)}`);
147
- // 模块化代码
148
- sjsModules.push(`".sjs#${moduleName}": function(exports,require,module,${index_1.SJS_HELPER}){${(result.code)};return module;}`);
149
- // 处理后的加入缓存
150
- sjsPathCache.add(sjsPath);
151
- }
152
- const source = new packs_1.ConcatSource(`globalThis['${sjsModuleName}'] = {`, `${sjsModules.join(',\n')}`, '}');
153
- if (packSetting.enableV1) {
154
- // @ts-ignore
155
- compilation.assets[`v1/${chunkName}`] = source;
156
- }
157
- if (packSetting.enableV2) {
158
- // @ts-ignore
159
- compilation.assets[`v2/${chunkName}`] = source;
160
- }
161
- }
162
- }
163
- exports.default = SjsEntryPlugin;
@@ -1,5 +0,0 @@
1
- import { Config } from 'xhs-mp-pack';
2
- import { IPresetOptions } from '../../../../types';
3
- declare const getServiceEntry: (options: any) => () => {};
4
- declare const presetService: (chain: Config, options: IPresetOptions) => void;
5
- export { getServiceEntry, presetService };