Skip to content

Commit

Permalink
smol improvements, patch bundle size
Browse files Browse the repository at this point in the history
  • Loading branch information
inetol committed Sep 14, 2024
1 parent 217ad7d commit 8a97223
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 53 deletions.
Binary file modified bun.lockb
Binary file not shown.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"@codemirror/view": "~6.33.0",
"@solid-primitives/media": "~2.2.9",
"@solid-primitives/storage": "~4.2.1",
"@swc/core": "~1.7.26",
"@tabler/icons-solidjs": "~3.16.0",
"@types/bun": "~1.1.9",
"@uiw/codemirror-extensions-hyper-link": "~4.23.2",
Expand All @@ -66,13 +65,16 @@
"typescript": "~5.6.2",
"vike": "~0.4.195",
"vike-solid": "~0.7.5",
"vite": "~5.4.4"
"vite": "~5.4.5"
},
"devDependencies": {
"@biomejs/biome": "~1.9.0",
"lefthook": "~1.7.15",
"sort-package-json": "~2.10.1"
},
"patchedDependencies": {
"@tabler/icons-solidjs@3.16.0": "patches/@tabler%2Ficons-solidjs@3.16.0.patch"
},
"trustedDependencies": [
"@biomejs/biome",
"lefthook"
Expand Down
12 changes: 12 additions & 0 deletions patches/@tabler%2Ficons-solidjs@3.16.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/package.json b/package.json
index 5df4273caa43cec18c53b77c6934b86f52b21e47..a3039433193efd197c7a5f745d7cf2ba24b8a5ff 100644
--- a/package.json
+++ b/package.json
@@ -20,6 +20,7 @@
"main": "./dist/cjs/tabler-icons-solidjs.cjs",
"module": "./dist/esm/tabler-icons-solidjs.mjs",
"types": "./dist/cjs/tabler-icons-solidjs.d.cts",
+ "sideEffects": false,
"files": [
"dist"
],
9 changes: 8 additions & 1 deletion scripts/compress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ await Promise.all(
const fileContent = await Bun.file(file).arrayBuffer();

console.debug('[COMPRESS] Compressing:', file);
await writeFile(`${file}.gz`, gzipSync(fileContent).buffer);

await writeFile(
`${file}.gz`,
gzipSync(fileContent, {
level: 9
}).buffer
);

await writeFile(`${file}.br`, brotliCompressSync(fileContent).buffer);
})
);
77 changes: 27 additions & 50 deletions scripts/minify.ts
Original file line number Diff line number Diff line change
@@ -1,68 +1,45 @@
import { transform } from '@swc/core';
import { findFiles, writeFile } from './utils.ts';
import { findFiles } from './utils.ts';

const serverAssets = async () => {
const rootStaticDirectory = './dist/server/';
const relativeStaticFilesPath = await findFiles(rootStaticDirectory, '**/*.js');
const rootStaticFilesPath = relativeStaticFilesPath.map((file) => rootStaticDirectory + file);

await Promise.all(
rootStaticFilesPath.map(async (file) => {
const min = await transform(await Bun.file(file).text(), {
isModule: true,
minify: true,
jsc: {
target: 'esnext',
minify: {
compress: {
arguments: true,
hoist_funs: true,
hoist_vars: true,
unsafe: true
},
format: {
comments: false
},
mangle: true
}
}
});
const result = await Bun.build({
entrypoints: rootStaticFilesPath,
target: 'bun',
format: 'esm',
splitting: false,
packages: 'external',
sourcemap: 'none',
minify: true
});

await writeFile(file, min.code);
})
);
if (!result.success) {
console.error(result.logs);
process.exit(1);
}
};

const clientAssets = async () => {
const rootStaticDirectory = './dist/client/';
const relativeStaticFilesPath = await findFiles(rootStaticDirectory, '**/*.js');
const rootStaticFilesPath = relativeStaticFilesPath.map((file) => rootStaticDirectory + file);

await Promise.all(
rootStaticFilesPath.map(async (file) => {
const min = await transform(await Bun.file(file).text(), {
isModule: true,
minify: true,
jsc: {
target: 'es2020',
minify: {
compress: {
arguments: true,
hoist_funs: true,
hoist_vars: true,
unsafe: true
},
format: {
comments: false
},
mangle: true
}
}
});
const result = await Bun.build({
entrypoints: rootStaticFilesPath,
target: 'browser',
format: 'esm',
splitting: false,
packages: 'external',
sourcemap: 'none',
minify: true
});

await writeFile(file, min.code);
})
);
if (!result.success) {
console.error(result.logs);
process.exit(1);
}
};

console.info('[MINIFY] Running...');
Expand Down

0 comments on commit 8a97223

Please sign in to comment.