Skip to content

Commit

Permalink
build: remove single-file inlining
Browse files Browse the repository at this point in the history
Compile JavaScript code as an IIFE, allowing us to avoid needing to
inline anything.

This makes the code about 10% faster for me
(tests run in 105s instead of 120s), and the size on the bundle went
from 4MiB to 3.5MiB.

Additionally, I think I've finally figured out the issue that was
sometimes causing the FontAwesome icons to load incorrectly: sometimes
Puppeteer was parsing the CSS FontAwesome as Latin-1 instead of UTF-8!
Explicility setting the script to have `charset="utf-8"` seems to fix
this!
  • Loading branch information
aloisklink authored and MindaugasLaganeckas committed Nov 12, 2024
1 parent 2fa163f commit 202d0b5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 266 deletions.
256 changes: 0 additions & 256 deletions package-lock.json

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

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
"standard": "^17.0.0",
"typescript": "^5.0.1-rc",
"vite": "^4.0.3",
"vite-plugin-singlefile": "^0.13.1",
"vite-svg-loader": "^5.1.0",
"yarn-upgrade-all": "^0.7.0"
},
"files": [
Expand Down
32 changes: 24 additions & 8 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
import { defineConfig } from "vite"
import { viteSingleFile } from "vite-plugin-singlefile"
import svgLoader from 'vite-svg-loader'

export default defineConfig({
base: './',
plugins: [
// bundle everything into a single `index.html`
viteSingleFile(),
// unsure if this is working properly for fontawesome fonts
svgLoader(),
],
})
{
name: 'IIFE-converter',
config(currentConfig, _unused) {
return {
...currentConfig,
build: {
...currentConfig.build,
rollupOptions: {
...currentConfig.build?.rollupOptions,
output: {
...currentConfig.build?.rollupOptions?.output,
format: 'iife',
}
}
}
};
},
transformIndexHtml(html) {
return html.replace('<script type="module" crossorigin', '<script charset="utf-8"')
}
}
]
});

0 comments on commit 202d0b5

Please sign in to comment.