-
Notifications
You must be signed in to change notification settings - Fork 10
Customizing a loader
Aritra Karak edited this page Oct 14, 2023
·
1 revision
Let's customize the behavior of the built-in Zig loader and make it log the the path of the source file every time it is run and log whenever the source file is built.
-
Create a new file called
myZigLoader.ts
. -
Inside we'll extend the built-in zig loader and swap out implementations with our custom ones by taking advantage of inheritance.
import { ZigLoader } from "hyperimport"; export default class extends ZigLoader { name = "My Zig Loader"; async build() { console.log("Building the source file..."); super.build(); console.log("Successfully built the source file!"); } async preload() { super.preload(); console.log("Importing", this.config.importPath, "..."); } }
-
Now we'll add this to custom in the hyperimport config.
[hyperimport] custom = ["./myZigLoader.ts"]
-
Import your zig file and run
bun .
to run index.ts. -
You'll find everytime the file is imported, it will log the message.
-
On changing the source file, the source file is rebuilt and that is too logged in the console.