hw-weapp-compiler 1.0.21 → 1.0.22
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.
|
@@ -34,12 +34,14 @@ module.exports = async function loader(source) {
|
|
|
34
34
|
return src ? [attr, src] : null;
|
|
35
35
|
}),
|
|
36
36
|
);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
// 路径可能互为后缀(如 a.png 与 icons/a.png),必须先替换较长路径,
|
|
38
|
+
// 否则短路径会破坏尚未处理的长路径。
|
|
39
|
+
const resolvedAssets = assetResults
|
|
40
|
+
.filter(Boolean)
|
|
41
|
+
.sort(([left], [right]) => right.length - left.length);
|
|
42
|
+
for (let index = 0; index < resolvedAssets.length; index += 1) {
|
|
43
|
+
const [attr, src] = resolvedAssets[index];
|
|
44
|
+
content = content.split(attr).join(withPublicPath(src));
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
// wxml文件 - 并行 loadModule
|
package/build/plugin/index.js
CHANGED
|
@@ -116,13 +116,13 @@ function injectGlobalModules(content, assetName, flags) {
|
|
|
116
116
|
'Function("r", "regeneratorRuntime = r")(runtime);',
|
|
117
117
|
'global.regeneratorRuntime = runtime',
|
|
118
118
|
);
|
|
119
|
-
if (
|
|
119
|
+
if (!result.includes("require('./commons.js');") && flags.hasCommonJs) {
|
|
120
120
|
result = `require('./commons.js');\n${result}`;
|
|
121
121
|
}
|
|
122
|
-
if (
|
|
122
|
+
if (!result.includes("require('./vendors.js');") && flags.hasVendorJs) {
|
|
123
123
|
result = `require('./vendors.js');\n${result}`;
|
|
124
124
|
}
|
|
125
|
-
if (
|
|
125
|
+
if (!result.includes("require('./runtime.js');") && flags.hasRuntimeJs) {
|
|
126
126
|
result = `require('./runtime.js');\n${result}`;
|
|
127
127
|
}
|
|
128
128
|
}
|
package/build/prod.js
CHANGED
|
@@ -2,7 +2,7 @@ const path = require('path');
|
|
|
2
2
|
const fse = require('fs-extra');
|
|
3
3
|
const { DIST_DIR } = require('../config/constants');
|
|
4
4
|
|
|
5
|
-
const KEEP_FILES = new Set(['
|
|
5
|
+
const KEEP_FILES = new Set(['weapp.env.json']);
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* 开发模式启动时清理 dist 旧产物。
|
|
@@ -69,7 +69,9 @@ function getWxmlAssets(filePath, content) {
|
|
|
69
69
|
const filteredAttrs = allAttrs
|
|
70
70
|
.filter((item) => !!item)
|
|
71
71
|
.map((item) => item.split('?')[0])
|
|
72
|
-
|
|
72
|
+
// http(s)、cloud、wxfile、data 等带协议资源均由小程序运行时处理,
|
|
73
|
+
// 只有本地相对路径、根路径和 webpack alias 才进入 resolver。
|
|
74
|
+
.filter((item) => !/^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(item))
|
|
73
75
|
.filter((item) => !/{{.*}}/.test(item))
|
|
74
76
|
.filter((item) => !/\+.*\+/.test(item));
|
|
75
77
|
|
package/build/utils/storage.js
CHANGED
|
@@ -4,18 +4,40 @@ const { debounce } = require('throttle-debounce');
|
|
|
4
4
|
|
|
5
5
|
const tempDir = path.resolve(process.cwd(), '.temp');
|
|
6
6
|
const uploadJsonDir = path.join(tempDir, 'upload.json');
|
|
7
|
+
const uploadJsonTempDir = `${uploadJsonDir}.${process.pid}.tmp`;
|
|
7
8
|
let uploadJson = {};
|
|
8
|
-
const writeUploadJsonDebounce = debounce(300, () => {
|
|
9
|
-
fs.writeJSONSync(uploadJsonDir, uploadJson);
|
|
10
|
-
});
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
function writeUploadJson() {
|
|
11
|
+
try {
|
|
12
|
+
fs.writeJSONSync(uploadJsonTempDir, uploadJson);
|
|
13
|
+
fs.renameSync(uploadJsonTempDir, uploadJsonDir);
|
|
14
|
+
} catch (error) {
|
|
15
|
+
try {
|
|
16
|
+
fs.removeSync(uploadJsonTempDir);
|
|
17
|
+
} catch (cleanupError) {
|
|
18
|
+
console.warn('清理上传缓存临时文件失败:', cleanupError);
|
|
19
|
+
}
|
|
20
|
+
console.warn('写入上传缓存失败,本次构建将继续:', error);
|
|
21
|
+
}
|
|
14
22
|
}
|
|
23
|
+
|
|
24
|
+
const writeUploadJsonDebounce = debounce(300, writeUploadJson);
|
|
25
|
+
|
|
26
|
+
fs.ensureDirSync(tempDir);
|
|
15
27
|
if (!fs.existsSync(uploadJsonDir)) {
|
|
16
|
-
|
|
28
|
+
writeUploadJson();
|
|
17
29
|
} else {
|
|
18
|
-
|
|
30
|
+
try {
|
|
31
|
+
const stored = fs.readJSONSync(uploadJsonDir);
|
|
32
|
+
if (!stored || Array.isArray(stored) || typeof stored !== 'object') {
|
|
33
|
+
throw new TypeError('上传缓存必须是 JSON 对象');
|
|
34
|
+
}
|
|
35
|
+
uploadJson = stored;
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.warn('上传缓存已损坏,将重建缓存:', error);
|
|
38
|
+
uploadJson = {};
|
|
39
|
+
writeUploadJson();
|
|
40
|
+
}
|
|
19
41
|
}
|
|
20
42
|
|
|
21
43
|
module.exports = {
|