forked from solidjs/solid-site
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostoptimize.mjs
More file actions
30 lines (27 loc) · 743 Bytes
/
postoptimize.mjs
File metadata and controls
30 lines (27 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { minifyFiles as jsonOptimize } from '@aminya/minijson';
import { optimize as svgOptimize } from 'svgo';
import { readFile, writeFile } from 'fs/promises';
import glob from 'fast-glob';
const svgFiles = await glob(['./dist/**/*.svg'], {
dot: true,
cwd: process.cwd(),
onlyFiles: true,
absolute: true,
});
const jsonFiles = await glob(['./dist/**/*.json'], {
dot: true,
cwd: process.cwd(),
onlyFiles: true,
absolute: true,
});
await Promise.all([
jsonOptimize(jsonFiles),
...svgFiles.map(async (svgFile) => {
const svgString = await readFile(svgFile, 'utf8');
const { data } = await svgOptimize(svgString, {
path: svgFile,
multipass: true,
});
await writeFile(svgFile, data);
}),
]);