Repository navigation
perf(storybook): improve deployed build performance #280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| *.ts whitespace=blank-at-eol,blank-at-eof,space-before-tab,cr-at-eol | ||
| *.tsx whitespace=blank-at-eol,blank-at-eof,space-before-tab,cr-at-eol | ||
| *.css whitespace=blank-at-eol,blank-at-eof,space-before-tab,cr-at-eol | ||
| *.js whitespace=blank-at-eol,blank-at-eof,space-before-tab,cr-at-eol | ||
| *.mjs whitespace=blank-at-eol,blank-at-eof,space-before-tab,cr-at-eol | ||
| *.json whitespace=blank-at-eol,blank-at-eof,space-before-tab,cr-at-eol |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,2 @@ | ||
| <title>@egdev6 Design System</title> | ||
| <link rel="icon" href="/images/favicon.svg" type="image/svg+xml"> | ||
| <link href="../src/styles/global.css" rel="stylesheet"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,27 @@ | ||
| [build] | ||
| command = "pnpm run storybook-build" | ||
| publish = "storybook-static" | ||
| publish = "storybook-static" | ||
|
|
||
| [[headers]] | ||
| for = "/" | ||
|
|
||
| [headers.values] | ||
| Cache-Control = "public, max-age=0, must-revalidate" | ||
|
|
||
| [[headers]] | ||
| for = "/index.html" | ||
|
|
||
| [headers.values] | ||
| Cache-Control = "public, max-age=0, must-revalidate" | ||
|
|
||
| [[headers]] | ||
| for = "/iframe.html" | ||
|
|
||
| [headers.values] | ||
| Cache-Control = "public, max-age=0, must-revalidate" | ||
|
|
||
| [[headers]] | ||
| for = "/assets/*" | ||
|
|
||
| [headers.values] | ||
| Cache-Control = "public, max-age=31536000, immutable" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import fs from 'node:fs'; | ||
| import path from 'node:path'; | ||
|
|
||
| const outputDir = path.resolve(process.cwd(), process.argv[2] ?? 'storybook-static'); | ||
|
|
||
| if (!fs.existsSync(outputDir)) { | ||
| console.error(`Storybook output directory not found: ${outputDir}`); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const formatBytes = (bytes) => { | ||
| if (bytes < 1024) { | ||
| return `${bytes} B`; | ||
| } | ||
|
|
||
| const units = ['KiB', 'MiB', 'GiB']; | ||
| let value = bytes; | ||
| let unitIndex = -1; | ||
|
|
||
| do { | ||
| value /= 1024; | ||
| unitIndex += 1; | ||
| } while (value >= 1024 && unitIndex < units.length - 1); | ||
|
|
||
| return `${value.toFixed(value >= 10 ? 1 : 2)} ${units[unitIndex]}`; | ||
| }; | ||
|
|
||
| const walk = (dir) => { | ||
| const entries = fs.readdirSync(dir, { withFileTypes: true }); | ||
|
|
||
| return entries.flatMap((entry) => { | ||
| const fullPath = path.join(dir, entry.name); | ||
|
|
||
| if (entry.isDirectory()) { | ||
| return walk(fullPath); | ||
| } | ||
|
|
||
| return [fullPath]; | ||
| }); | ||
| }; | ||
|
|
||
| const files = walk(outputDir).map((fullPath) => { | ||
| const stats = fs.statSync(fullPath); | ||
|
|
||
| return { | ||
| fullPath, | ||
| relativePath: path.relative(outputDir, fullPath), | ||
| size: stats.size | ||
| }; | ||
| }); | ||
|
|
||
| const totalBytes = files.reduce((sum, file) => sum + file.size, 0); | ||
| const jsFiles = files.filter((file) => file.relativePath.endsWith('.js')); | ||
| const jsBytes = jsFiles.reduce((sum, file) => sum + file.size, 0); | ||
| const topAssets = files | ||
| .filter((file) => file.relativePath.startsWith('assets/')) | ||
| .sort((a, b) => b.size - a.size) | ||
| .slice(0, 10); | ||
|
|
||
| console.log('Storybook build report'); | ||
| console.log(`Directory: ${outputDir}`); | ||
| console.log(`Total size: ${formatBytes(totalBytes)} (${totalBytes} bytes)`); | ||
| console.log(`JavaScript files: ${jsFiles.length}`); | ||
| console.log(`Raw JavaScript size: ${formatBytes(jsBytes)} (${jsBytes} bytes)`); | ||
| console.log('Top assets:'); | ||
|
|
||
| for (const asset of topAssets) { | ||
| console.log(`- ${formatBytes(asset.size)} ${asset.relativePath}`); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.