Skip to content

Commit

Permalink
add basic optimization for skipping favicons on rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
scheibo committed Nov 7, 2023
1 parent caabae5 commit 5e87e86
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if (process.env.NODE_ENV === 'development') {
format: 'cjs',
});
const compile = `${(Math.round(Number(process.hrtime.bigint() - begin) / 1e6))} ms`;
execFileSync('node', ['build/static/build.js'], {
execFileSync('node', ['build/static/build.js', '--rebuild'], {
encoding: 'utf8',
stdio: 'pipe',
cwd: ROOT,
Expand Down
16 changes: 9 additions & 7 deletions src/static/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const render = (name: string, page: Page) => {
return minified;
};

export const write = (name: string, page: Page) => {
const write = (name: string, page: Page) => {
fs.mkdirSync(path.join(PUBLIC, name), {recursive: true});
fs.writeFileSync(path.join(PUBLIC, name, 'index.html'), render(name, page));
};
Expand All @@ -71,13 +71,15 @@ const toHTML = (file: string) =>
},
});

export const build = async () => {
const build = async (rebuild?: boolean) => {
fs.mkdirSync(path.join(PUBLIC), {recursive: true});

const icons = await favicons(path.join(STATIC, 'favicon.svg'), {path: PUBLIC});
for (const icon of icons.images) {
if (/(yandex|apple)/.test(icon.name)) continue;
fs.writeFileSync(path.join(PUBLIC, icon.name), icon.contents);
if (!rebuild) {
const icons = await favicons(path.join(STATIC, 'favicon.svg'), {path: PUBLIC});
for (const icon of icons.images) {
if (/(yandex|apple)/.test(icon.name)) continue;
fs.writeFileSync(path.join(PUBLIC, icon.name), icon.contents);
}
}

const index = fs.readFileSync(path.join(STATIC, 'index.css'), 'utf8');
Expand Down Expand Up @@ -135,7 +137,7 @@ export const build = async () => {

if (require.main === module) {
(async () => {
await build();
await build(process.argv[2] === '--rebuild');
})().catch(err => {
console.error(err);
process.exit(1);
Expand Down

0 comments on commit 5e87e86

Please sign in to comment.