-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: 优化
build/info.ts
文件中的一些函数,使其友好支持esm
- Loading branch information
1 parent
a9257d3
commit 2a3fa34
Showing
2 changed files
with
38 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { readdir, stat } from "node:fs"; | ||
import { sum, formatBytes } from "@pureadmin/utils"; | ||
|
||
const fileListTotal: number[] = []; | ||
|
||
/** | ||
* @description 获取指定文件夹中所有文件的总大小 | ||
*/ | ||
export const getPackageSize = options => { | ||
const { folder = "dist", callback, format = true } = options; | ||
readdir(folder, (err, files: string[]) => { | ||
if (err) throw err; | ||
let count = 0; | ||
const checkEnd = () => { | ||
++count == files.length && | ||
callback(format ? formatBytes(sum(fileListTotal)) : sum(fileListTotal)); | ||
}; | ||
files.forEach((item: string) => { | ||
stat(`${folder}/${item}`, async (err, stats) => { | ||
if (err) throw err; | ||
if (stats.isFile()) { | ||
fileListTotal.push(stats.size); | ||
checkEnd(); | ||
} else if (stats.isDirectory()) { | ||
getPackageSize({ | ||
folder: `${folder}/${item}/`, | ||
callback: checkEnd | ||
}); | ||
} | ||
}); | ||
}); | ||
files.length === 0 && callback(0); | ||
}); | ||
}; |
2a3fa34
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为后续升级
vite5
以及vite.config.ts
文件名改为vite.config.mts
做准备#738 (comment)