Skip to content

Commit 1a30c78

Browse files
committed
fix: 修复webpack banner处理逻辑
1. 解决banner.txt第一行内容没有添加注释前缀的问题\n2. 优化banner处理逻辑,使用map处理每一行内容\n3. 确保油猴脚本头部注释与banner之间有足够空行
1 parent 6cb42ec commit 1a30c78

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

banner.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
▗▄▄▄▖▗▖ ▗▖▗▄▄▖ ▗▄▄▄▖ ▗▄▄▖ ▗▄▄▖▗▄▄▖ ▗▄▄▄▖▗▄▄▖▗▄▄▄▖
32
█ ▝▚▞▘ ▐▌ ▐▌▐▌ ▐▌ ▐▌ ▐▌ ▐▌ █ ▐▌ ▐▌ █
43
█ ▐▌ ▐▛▀▘ ▐▛▀▀▘ ▝▀▚▖▐▌ ▐▛▀▚▖ █ ▐▛▀▘ █

webpack.common.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,17 @@ module.exports = {
4646
banner = banner.replaceAll("${document}", webpackPackageJson["document"] || "");
4747
banner = banner.replaceAll("${author}", webpackPackageJson["author"] || "");
4848
banner = banner.replaceAll("${repository}", webpackPackageJson["repository"] || "");
49-
userscriptHeaders += "\n" + banner.split("\n").join("\n// ") + "\n";
49+
50+
// 修复:确保在油猴头部注释和banner之间有足够的空行
51+
// 添加两个换行,确保脚本头注释和实际代码之间有明确的分隔
52+
// 修复:确保每一行都添加注释前缀,包括第一行
53+
userscriptHeaders += "\n\n";
54+
55+
// 处理每一行,确保每一行都有注释前缀
56+
const bannerLines = banner.split("\n");
57+
const commentedBanner = bannerLines.map(line => "// " + line).join("\n");
58+
59+
userscriptHeaders += commentedBanner + "\n";
5060
}
5161

5262
return userscriptHeaders;

0 commit comments

Comments
 (0)