refactor(css): #6 后续阶段——@layer 级联 + token 化 + 行尾治理
- 引入 @layer ecommerce-core,standalone 覆盖层不再依赖 !important(全站 !important 7812→967)
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Remove all !important declarations from a CSS file.
|
||||
* For use with base.css and other files that no longer need !important
|
||||
* because they are unlayered and override layered ecommerce.css by cascade priority.
|
||||
*/
|
||||
|
||||
import { readFileSync, writeFileSync } from "node:fs";
|
||||
|
||||
const filePath = process.argv[2];
|
||||
if (!filePath) {
|
||||
console.error("Usage: node cleanup-css-important.mjs <file.css>");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
let content = readFileSync(filePath, "utf-8");
|
||||
|
||||
// Strip BOM
|
||||
content = content.replace(/^\uFEFF/, "");
|
||||
|
||||
// Remove !important
|
||||
const before = (content.match(/!important/g) || []).length;
|
||||
content = content.replace(/\s*!important/g, "");
|
||||
|
||||
// Fix artifacts
|
||||
content = content.replace(/;\s*;/g, ";");
|
||||
content = content.replace(/;\s*}/g, "}");
|
||||
content = content.replace(/[ \t]+$/gm, "");
|
||||
|
||||
const after = (content.match(/!important/g) || []).length;
|
||||
const lines = content.split("\n").length;
|
||||
|
||||
writeFileSync(filePath, content, "utf-8");
|
||||
|
||||
console.log(`Processed: ${filePath}`);
|
||||
console.log(` Lines: ${lines}`);
|
||||
console.log(` !important: ${before} → ${after} (removed ${before - after})`);
|
||||
Reference in New Issue
Block a user