chore:产物输出到dist目录

This commit is contained in:
2025-12-22 09:24:30 +08:00
parent 8521263760
commit ea3e2d9ae8
2 changed files with 52 additions and 0 deletions

52
compress-wxml.js Normal file
View File

@@ -0,0 +1,52 @@
const fs = require('fs');
const path = require('path');
// 定义要压缩的目录
const rootDir = __dirname;
// 定义wxml压缩函数
function compressWxml(content) {
// 移除HTML注释
content = content.replace(/<!--[\s\S]*?-->/g, '');
// 移除多余的空白字符(空格、换行、制表符)
// 保留标签内的必要空格
content = content.replace(/\s+/g, ' ');
// 移除标签前后的空格
content = content.replace(/\s*</g, '<');
content = content.replace(/>\s*/g, '>');
return content;
}
// 递归遍历目录并压缩wxml文件
function traverseDir(dir) {
const files = fs.readdirSync(dir);
files.forEach(file => {
const filePath = path.join(dir, file);
const stats = fs.statSync(filePath);
if (stats.isDirectory()) {
// 跳过node_modules和其他不需要处理的目录
if (file !== 'node_modules' && file !== '.git' && file !== 'dist') {
traverseDir(filePath);
}
} else if (path.extname(file) === '.wxml') {
// 读取并压缩wxml文件
const content = fs.readFileSync(filePath, 'utf8');
const compressedContent = compressWxml(content);
// 写回压缩后的内容
fs.writeFileSync(filePath, compressedContent, 'utf8');
console.log(`Compressed: ${filePath}`);
}
});
}
// 开始压缩
console.log('Start compressing wxml files...');
traverseDir(rootDir);
console.log('All wxml files compressed successfully!');