The `preload` option in the `bunfig.toml` file is used to specify an array of scripts or plugins that should be executed before running any other code in a Bun project. This feature allows developers to set up necessary configurations, dependencies, or environment settings that need to be in place before the main application logic starts executing.
Usage of `preload`
For example, you can configure the `preload` option as follows:
toml
preload = ["./preload.ts"]
In this configuration, Bun will execute the `preload.ts` script prior to running any other code when you use commands like `bun run`. This is particularly useful for initializing settings, registering plugins, or setting up testing environments that require specific configurations before the main application logic is executed[1][3][6].
Overall, the `preload` feature enhances the flexibility and configurability of Bun, allowing developers to tailor their runtime environment according to their project's needs.
Citations:[1] https://betterstack.com/community/guides/scaling-nodejs/introduction-to-bun-for-nodejs-users/
[2] https://github.com/oven-sh/bun/issues/12608
[3] https://bun.sh/docs/runtime/bunfig
[4] https://github.com/oven-sh/bun/issues/6297
[5] https://stackoverflow.com/questions/77087225/how-to-add-save-exact-in-bunfig-toml/77092349
[6] https://www.telerik.com/blogs/getting-started-bun-react-developers
[7] https://socket.dev/npm/package/bun-plugin-env-types
[8] https://www.linkedin.com/posts/heyandree_apparently-you-can-install-your-packages-activity-7199710747055067139-b7_i