Skip to content

Commit 0053f2e

Browse files
committed
chore: dist file size chekcing with github actions
1 parent 8dc19e0 commit 0053f2e

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

scripts/build.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,27 @@ const {
8484
} = values
8585

8686
const formats = rawFormats?.split(',')
87+
const sizeDir = path.resolve(__dirname, '../temp/size')
8788

8889
async function main() {
8990
await run()
9091

9192
async function run() {
93+
if (size) {
94+
await fs.mkdir(sizeDir, { recursive: true })
95+
}
96+
9297
const rtsCachePath = path.resolve(__dirname, './node_modules/.rts2_cache')
9398
if (isRelease && existsSync(rtsCachePath)) {
9499
// remove build cache for release builds to avoid outdated enum values
95100
await fs.rm(rtsCachePath, { recursive: true })
96101
}
102+
97103
const resolvedTargets = targets.length
98104
? await fuzzyMatchTarget(targets, buildAllMatching)
99105
: await allTargets()
100106
await buildAll(resolvedTargets)
107+
101108
if (size) {
102109
await checkAllSizes(resolvedTargets)
103110
}
@@ -273,6 +280,8 @@ async function main() {
273280
return
274281
}
275282
const file = await fs.readFile(filePath)
283+
const filename = path.basename(filePath)
284+
276285
const minSize = (file.length / 1024).toFixed(2) + 'kb'
277286
const gzipped = gzipSync(file)
278287
const gzippedSize = (gzipped.length / 1024).toFixed(2) + 'kb'
@@ -284,6 +293,24 @@ async function main() {
284293
pc.bold(path.basename(filePath))
285294
)} min:${minSize} / gzip:${gzippedSize} / brotli:${compressedSize}`
286295
)
296+
297+
if (size) {
298+
const sizeContents = JSON.stringify(
299+
{
300+
file: filename,
301+
size: file.length,
302+
gzip: gzipped.length,
303+
brotli: compressed.length
304+
},
305+
null,
306+
2
307+
)
308+
await fs.writeFile(
309+
path.resolve(sizeDir, `${filename}.json`),
310+
sizeContents,
311+
'utf-8'
312+
)
313+
}
287314
}
288315
}
289316

scripts/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ export const fuzzyMatchTarget = async (
5656

5757
export async function checkSizeDistFiles(target: string) {
5858
const dirs = await fs.readdir(`${target}/dist`)
59-
return dirs.filter(file => /prod.(cjs|js)$/.test(file))
59+
// prettier-ignore
60+
return dirs.filter(file => /^(message-compiler|core|vue-i18n|petite-vue-i18n)/.test(file))
61+
.filter(file => !/^core-base/.test(file))
62+
.filter(file => /prod.(cjs|js)$/.test(file))
63+
.filter(file => !/cjs.prod.js$/.test(file))
6064
}
6165

6266
export async function readJson(path: string) {

0 commit comments

Comments
 (0)