Skip to content

Commit

Permalink
Better bundle size prediction
Browse files Browse the repository at this point in the history
  • Loading branch information
PuruVJ committed Sep 13, 2022
1 parent 8e4d3e2 commit c8359e9
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 12 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,19 @@
],
"scripts": {
"dev": "vite dev",
"build": "vite build",
"build": "vite build -l silent && cd scripts && tsm size.ts",
"package": "svelte-package",
"pub": "pnpm package && cd scripts && tsm clean-pkg.ts && cd ../package && pnpm publish",
"preview": "vite preview"
},
"devDependencies": {
"@sveltejs/kit": "next",
"@sveltejs/package": "next",
"brotli-size": "^4.0.0",
"sass": "^1.54.9",
"svelte": "^3.50.1",
"svelte-preprocess": "^4.10.7",
"svelte2tsx": "^0.5.16",
"terser": "^5.15.0",
"tslib": "^2.4.0",
"tsm": "^2.2.2",
"typescript": "^4.8.3",
Expand Down
106 changes: 97 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions scripts/size.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { fileSync } from 'brotli-size';
import { readdirSync } from 'fs';

const jsRootPath = '../.svelte-kit/output/client/_app/immutable/chunks';
const jsFile =
jsRootPath +
'/' +
readdirSync(jsRootPath, {
withFileTypes: true,
}).find((dirent) => dirent.name.includes('ConfettiExplosion'))?.name;

const jsSize = (fileSync(jsFile) / 1024).toFixed(2);
console.log('JS Size:', jsSize);

const cssRootPath = '../.svelte-kit/output/client/_app/immutable/assets';
const cssFile =
cssRootPath +
'/' +
readdirSync(cssRootPath, {
withFileTypes: true,
}).find((dirent) => dirent.name.includes('ConfettiExplosion'))?.name;

const cssSize = (fileSync(cssFile) / 1024).toFixed(2);
console.log('CSS Size:', cssSize);

console.log('\n\n');

console.log('Combined size: ', +jsSize + +cssSize);
2 changes: 2 additions & 0 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
/>
</div>

<a href="/extra-page" hidden>Another page</a>

<style lang="scss">
:global(body) {
overflow: hidden;
Expand Down
5 changes: 5 additions & 0 deletions src/routes/extra-page/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
import { ConfettiExplosion } from '$lib';
</script>

<ConfettiExplosion />
3 changes: 2 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { sveltekit } from '@sveltejs/kit/vite';
import type { UserConfig } from 'vite';

const config: UserConfig = {
plugins: [sveltekit()]
plugins: [sveltekit()],
build: { reportCompressedSize: true, minify: 'terser' },
};

export default config;

0 comments on commit c8359e9

Please sign in to comment.