xhs-mp-compiler-cli 1.9.8 → 1.9.9

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.
@@ -21,9 +21,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
21
21
  __setModuleDefault(result, mod);
22
22
  return result;
23
23
  };
24
- var __importDefault = (this && this.__importDefault) || function (mod) {
25
- return (mod && mod.__esModule) ? mod : { "default": mod };
26
- };
27
24
  (function (factory) {
28
25
  if (typeof module === "object" && typeof module.exports === "object") {
29
26
  var v = factory(require, exports);
@@ -35,12 +32,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
35
32
  })(function (require, exports) {
36
33
  "use strict";
37
34
  Object.defineProperty(exports, "__esModule", { value: true });
38
- const fs_extra_1 = __importDefault(require("fs-extra"));
35
+ const fs_extra_1 = __importStar(require("fs-extra"));
39
36
  const path_1 = __importStar(require("path"));
40
37
  const xhs_mp_pack_1 = require("xhs-mp-pack");
41
38
  const loader_utils_1 = require("../../utils/loader-utils");
42
39
  const getSuffixName_1 = require("../../utils/getSuffixName");
43
- function genComponentLoaderScript(project, packSetting, context, opts) {
40
+ function genComponentLoaderScript(project, context, opts) {
44
41
  const { pkg, root, mode, compPath } = opts;
45
42
  const { projectMiniprogramPath, jsonDependencies = [] } = project;
46
43
  const componentsMap = project.getComponentsMap();
@@ -77,24 +74,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
77
74
  ;${entries.join('\n ')}
78
75
  `;
79
76
  }
80
- const genRenderLoaderScript = (project, packSetting, context, opts) => {
77
+ const genRenderLoaderScript = (project, context, opts) => {
81
78
  const { projectMiniprogramPath, appJSON, jsonDependencies } = project;
82
- const { enableVDom } = packSetting;
83
79
  const { pkg, mode } = opts;
84
80
  const isFull = pkg === 'full';
85
- const appCssPath = (0, path_1.resolve)(projectMiniprogramPath, 'app.css');
86
81
  for (const file of jsonDependencies) {
87
82
  context.addDependency(file);
88
83
  }
84
+ const appCssPath = (0, path_1.resolve)(projectMiniprogramPath, 'app.css');
85
+ const appCssExist = (0, fs_extra_1.existsSync)(appCssPath);
89
86
  const resourcePath = (0, loader_utils_1.formatPath)(context.resourcePath);
90
87
  const path = (0, loader_utils_1.formatPath)(resourcePath.replace(`${projectMiniprogramPath}/`, '').replace(`.${(0, getSuffixName_1.getMlSuffixName)()}`, ''));
91
88
  const subPackage = (appJSON.subPackages || []).find(subPack => !!subPack.pages.find(page => page.path === path));
92
89
  const enableLazyCodeLoading = mode === 'v2';
93
90
  // 资源文件
94
- const { resourceList, appCssCode } = (0, loader_utils_1.getResourceUris)({
95
- appCssPath,
91
+ const resources = (0, loader_utils_1.getResourceUris)({
92
+ appCssExist,
96
93
  subPackage,
97
- enableVDom,
98
94
  enableLazyCodeLoading
99
95
  });
100
96
  // 开启了按需注入,注入依赖组件
@@ -112,18 +108,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
112
108
  depends.push(uri);
113
109
  }
114
110
  return `
115
- ${appCssCode};
116
111
  import Component from '${resourcePath}';
117
- globalThis.__render.mount(Component, '${path}', ${JSON.stringify(resourceList)}, ${JSON.stringify(depends)})
112
+ globalThis.__render.mount(Component, '${path}', ${JSON.stringify(resources)}, ${JSON.stringify(depends)})
118
113
  `;
119
114
  }
120
115
  return `
121
- ${appCssCode}
122
116
  import Component from '${resourcePath}';
123
- globalThis.__render.mount(Component, '${path}', ${JSON.stringify(resourceList)})
117
+ globalThis.__render.mount(Component, '${path}', ${JSON.stringify(resources)})
124
118
  `;
125
119
  };
126
- function genServiceLoderScript(project, packSetting, context, opts) {
120
+ function genServiceLoderScript(project, context, opts) {
127
121
  const { appJSON, legacyAppJSON, projectMiniprogramPath, jsonDependencies } = project;
128
122
  const { pkg, root } = opts;
129
123
  const modules = [];
@@ -137,8 +131,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
137
131
  const addAppJs = () => {
138
132
  if (fs_extra_1.default.existsSync(`${projectMiniprogramPath}/app.js`) ||
139
133
  fs_extra_1.default.existsSync(`${projectMiniprogramPath}/app.ts`)) {
140
- modules.unshift(`const loadAppJs = () => require('${(0, loader_utils_1.formatPath)(`${projectMiniprogramPath}/app`)}');` +
141
- `globalThis['${name}'].default['app'] = globalThis.xhsLazyAppJs ? loadAppJs : loadAppJs()`);
134
+ modules.unshift(`;globalThis['${name}'].default['app'] = require('${(0, loader_utils_1.formatPath)(`${projectMiniprogramPath}/app`)}')`);
142
135
  }
143
136
  };
144
137
  if (pkg === xhs_mp_pack_1.CONSTANTS.FULL_PKG) {
@@ -205,7 +198,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
205
198
  if (!handler) {
206
199
  throw new Error(`not found loader handler of ${type}`);
207
200
  }
208
- return handler(this._compiler.project, this._compiler.packSetting, this, options);
201
+ return handler(this._compiler.project, this, options);
209
202
  }
210
203
  module.exports = entryLoader;
211
204
  });
@@ -4,14 +4,10 @@ export declare const getShortPath: (projectMiniprogramPath: string, rootContext:
4
4
  * 根据是否分包获取资源路径
5
5
  */
6
6
  export declare const getResourceUris: (options: {
7
- appCssPath: string;
8
- enableVDom: boolean;
7
+ appCssExist: boolean;
9
8
  enableLazyCodeLoading: boolean;
10
9
  subPackage: any;
11
- }) => {
12
- appCssCode: string;
13
- resourceList: string[];
14
- };
10
+ }) => string[];
15
11
  /**
16
12
  * @NOTE
17
13
  * Create a request and handle the conversion of esModule modules
@@ -7,7 +7,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
7
7
  if (v !== undefined) module.exports = v;
8
8
  }
9
9
  else if (typeof define === "function" && define.amd) {
10
- define(["require", "exports", "path", "./common", "./getSuffixName", "fs-extra"], factory);
10
+ define(["require", "exports", "path", "./common", "./getSuffixName"], factory);
11
11
  }
12
12
  })(function (require, exports) {
13
13
  "use strict";
@@ -17,7 +17,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  const path_1 = __importDefault(require("path"));
18
18
  const common_1 = require("./common");
19
19
  const getSuffixName_1 = require("./getSuffixName");
20
- const fs_extra_1 = __importDefault(require("fs-extra"));
21
20
  const formatPath = (pathStr = '') => pathStr.split(path_1.default.sep).join(path_1.default.posix.sep);
22
21
  exports.formatPath = formatPath;
23
22
  const getShortPath = (projectMiniprogramPath, rootContext) => {
@@ -35,26 +34,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
35
34
  */
36
35
  const getResourceUris = (options) => {
37
36
  const resourceList = [];
38
- const { appCssPath, enableVDom, enableLazyCodeLoading, subPackage } = options;
39
- const appCssExist = fs_extra_1.default.existsSync(appCssPath);
37
+ const { appCssExist, enableLazyCodeLoading, subPackage } = options;
40
38
  // sjs 无法识别是否引用 所以一律push
41
- // 加载顺序 主包sjs 分包sjs 主包components.js 分包components.js
42
- let appCssCode = '';
43
- const genAppCss = () => {
44
- if (appCssExist) {
45
- // 运行时v2架构下,还是传递给运行时控制
46
- if (enableVDom) {
47
- resourceList.push(`app.css`);
48
- }
49
- else {
50
- // 运行时v1架构下,需要放在appCssCode,避免页面样式优先级高于app.css
51
- appCssCode = `import '${(0, exports.formatPath)(appCssPath)}'`;
52
- }
53
- }
54
- };
39
+ // 加载顺序 app.css 主包sjs 分包sjs 主包components.js 分包components.js
55
40
  if (!subPackage) {
56
41
  // 主包
57
- genAppCss();
42
+ appCssExist && resourceList.push(`app.css`);
58
43
  resourceList.push('sjs.js');
59
44
  !enableLazyCodeLoading && resourceList.push(`components.js`);
60
45
  }
@@ -64,14 +49,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
64
49
  !enableLazyCodeLoading && resourceList.push(`${subPackage === null || subPackage === void 0 ? void 0 : subPackage.root}/components.js`);
65
50
  }
66
51
  else if (subPackage) {
67
- // 普通分包, 自己的components.js,主包components.js
68
- genAppCss();
52
+ // 普通分包, 自己的components.js,主包components.js app.css
53
+ appCssExist && resourceList.push(`app.css`);
69
54
  resourceList.push('sjs.js');
70
55
  resourceList.push(`${subPackage === null || subPackage === void 0 ? void 0 : subPackage.root}/sjs.js`);
71
56
  !enableLazyCodeLoading && resourceList.push(`components.js`);
72
57
  !enableLazyCodeLoading && resourceList.push(`${subPackage === null || subPackage === void 0 ? void 0 : subPackage.root}/components.js`);
73
58
  }
74
- return { appCssCode, resourceList };
59
+ return resourceList;
75
60
  };
76
61
  exports.getResourceUris = getResourceUris;
77
62
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xhs-mp-compiler-cli",
3
- "version": "1.9.8",
3
+ "version": "1.9.9",
4
4
  "description": "xhs mp command tool.",
5
5
  "preferGlobal": true,
6
6
  "category": "esm",
@@ -94,13 +94,13 @@
94
94
  "webpack-chain": "^6.5.1",
95
95
  "webpack-sources": "^3.2.2",
96
96
  "xhs-mp-workerpool": "^9.1.3",
97
- "xhs-mp-compiler-ml-loader": "3.0.8",
98
- "xhs-mp-compiler-utils": "1.9.8",
99
- "xhs-mp-pack": "1.9.8",
100
- "xhs-mp-project": "1.9.8",
101
- "xhs-mp-utils": "1.9.8",
102
- "xhs-mp-shared-fs": "1.4.8",
103
- "xhs-mp-compiler-sjs-loader": "1.9.8",
97
+ "xhs-mp-compiler-ml-loader": "3.0.9",
98
+ "xhs-mp-compiler-utils": "1.9.9",
99
+ "xhs-mp-pack": "1.9.9",
100
+ "xhs-mp-project": "1.9.9",
101
+ "xhs-mp-utils": "1.9.9",
102
+ "xhs-mp-shared-fs": "1.4.9",
103
+ "xhs-mp-compiler-sjs-loader": "1.9.9",
104
104
  "yauzl": "^2.10.0"
105
105
  },
106
106
  "devDependencies": {