-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
2fa163f
commit 202d0b5
Showing
3 changed files
with
24 additions
and
266 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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,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"') | ||
} | ||
} | ||
] | ||
}); |