xhs-mp-compiler-cli 1.9.9 → 1.9.10
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.
|
@@ -10,17 +10,43 @@
|
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const packs_1 = require("../../../../packs");
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
/**
|
|
14
|
+
* 注入变量不可以使用 let const var 变量形式
|
|
15
|
+
* 因为2.0 架构下 render.js 和 component.js 运行在逻辑层(只有一个环境) 会导致变量冲突
|
|
16
|
+
*/
|
|
17
|
+
const common = `
|
|
18
|
+
globalThis.__XHS_WEBVIEW = (globalThis.localStorage && globalThis.document && globalThis.document.querySelectorAll);
|
|
19
|
+
`;
|
|
20
|
+
const injectLink = `
|
|
21
|
+
${common}
|
|
22
|
+
globalThis.__XHS_ADD_LINK = function(src){
|
|
23
|
+
if (!globalThis.__XHS_WEBVIEW) return;
|
|
24
|
+
const host = globalThis.SmallApp && globalThis.SmallApp.__BOOTSTRAP_HOST__
|
|
25
|
+
const link = document.createElement('link')
|
|
26
|
+
link.href = host + "/" + src
|
|
27
|
+
link.type = 'text/css'
|
|
28
|
+
link.rel = 'stylesheet'
|
|
29
|
+
link.setAttribute('xhs-p', src)
|
|
30
|
+
document.head.appendChild(link);
|
|
31
|
+
};
|
|
32
|
+
`;
|
|
33
|
+
/**
|
|
34
|
+
* 2.0模式下 render.js 和 component.js 运行在逻辑层
|
|
35
|
+
* 目前 2.0 各项功能已经稳定 降级可能性不大
|
|
36
|
+
* 2.0中原先css打包了两份 一份是 .css 文件 一份是 在render.js中注入的style标签
|
|
37
|
+
* 现在2.0 打包 render.js 中改为使用link标签注入,这样降级到 1.0 时仍然正常运行
|
|
38
|
+
* 且不会使得包体积变大
|
|
39
|
+
* 2.0 后面量起来后,可全部采用加载link方式打包,不必区分1.0 2.0
|
|
40
|
+
*/
|
|
41
|
+
const injectStyle = `
|
|
42
|
+
${common}
|
|
43
|
+
globalThis.__XHS_ADD_STYLE = function(style, src){
|
|
44
|
+
if (!globalThis.__XHS_WEBVIEW) return;
|
|
45
|
+
const cssTextNode = document.createTextNode(String(style))
|
|
46
|
+
const styleNode = document.createElement('style')
|
|
47
|
+
styleNode.setAttribute('xhs-p', src)
|
|
22
48
|
styleNode.appendChild(cssTextNode)
|
|
23
|
-
head.appendChild(styleNode)
|
|
49
|
+
document.head.appendChild(styleNode)
|
|
24
50
|
};
|
|
25
51
|
`;
|
|
26
52
|
// 注入css跟webpack runtime
|
|
@@ -35,9 +61,9 @@ globalThis.__XHS_APPEND_CSS = function(cssText, src){
|
|
|
35
61
|
stage: packs_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
|
|
36
62
|
}, assets => {
|
|
37
63
|
var _a, _b;
|
|
38
|
-
const { project } = this.options;
|
|
64
|
+
const { project, packSetting } = this.options;
|
|
39
65
|
// 注入css逻辑
|
|
40
|
-
const injectCode =
|
|
66
|
+
const injectCode = packSetting.enableVDom ? injectLink : injectStyle;
|
|
41
67
|
const appJSON = project.appJSON;
|
|
42
68
|
const pathMap = [
|
|
43
69
|
(_a = appJSON.pages) === null || _a === void 0 ? void 0 : _a.map(({ path }) => path),
|
|
@@ -67,8 +67,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
67
67
|
return `export default void 0;`;
|
|
68
68
|
}
|
|
69
69
|
// 判断浏览器环境,注入css添加逻辑
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
if (enableVDom) {
|
|
71
|
+
return new packs_1.RawSource(`globalThis.__XHS_ADD_LINK(${JSON.stringify(shortPath)});` +
|
|
72
|
+
`export default ${JSON.stringify(shortPath)};`).source();
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
return new packs_1.RawSource(`globalThis.__XHS_ADD_STYLE(${JSON.stringify(code)}, ${JSON.stringify(shortPath)});` +
|
|
76
|
+
`export default ${JSON.stringify(shortPath)};`).source();
|
|
77
|
+
}
|
|
72
78
|
};
|
|
73
79
|
if (packSetting.compressCss) {
|
|
74
80
|
// 压缩css
|
|
@@ -131,7 +131,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
131
131
|
const addAppJs = () => {
|
|
132
132
|
if (fs_extra_1.default.existsSync(`${projectMiniprogramPath}/app.js`) ||
|
|
133
133
|
fs_extra_1.default.existsSync(`${projectMiniprogramPath}/app.ts`)) {
|
|
134
|
-
modules.unshift(
|
|
134
|
+
modules.unshift(`const loadAppJs = () => require('${(0, loader_utils_1.formatPath)(`${projectMiniprogramPath}/app`)}');` +
|
|
135
|
+
`globalThis['${name}'].default['app'] = globalThis.xhsLazyAppJs ? loadAppJs : loadAppJs()`);
|
|
135
136
|
}
|
|
136
137
|
};
|
|
137
138
|
if (pkg === xhs_mp_pack_1.CONSTANTS.FULL_PKG) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xhs-mp-compiler-cli",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.10",
|
|
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.
|
|
98
|
-
"xhs-mp-compiler-utils": "1.9.
|
|
99
|
-
"xhs-mp-pack": "1.9.
|
|
100
|
-
"xhs-mp-project": "1.9.
|
|
101
|
-
"xhs-mp-utils": "1.9.
|
|
102
|
-
"xhs-mp-shared-fs": "1.4.
|
|
103
|
-
"xhs-mp-compiler-sjs-loader": "1.9.
|
|
97
|
+
"xhs-mp-compiler-ml-loader": "3.0.10",
|
|
98
|
+
"xhs-mp-compiler-utils": "1.9.10",
|
|
99
|
+
"xhs-mp-pack": "1.9.10",
|
|
100
|
+
"xhs-mp-project": "1.9.10",
|
|
101
|
+
"xhs-mp-utils": "1.9.10",
|
|
102
|
+
"xhs-mp-shared-fs": "1.4.10",
|
|
103
|
+
"xhs-mp-compiler-sjs-loader": "1.9.10",
|
|
104
104
|
"yauzl": "^2.10.0"
|
|
105
105
|
},
|
|
106
106
|
"devDependencies": {
|