Skip to content

Importing a package

Aritra Karak edited this page Nov 8, 2023 · 2 revisions

In this guide, we will import the yaml package from the hyperimport registry.

  1. Create a new project with bun init.

  2. Install hyperimport in your project.

    bun i hyperimport
    
  3. Create a new file called bunfig.toml and add the preload script.

    preload = ["./node_modules/hyperimport/preload.ts"]
  4. Add the yaml package to the config below that.

    [hyperimport]
    packages = ["yaml"]
  5. Create a new file called data.yml with the following data.

    name: Fast X
    releaseYear: 2023
  6. Inside index.ts import this file.

    import data from "./data.yml";
    console.log(data);
  7. Finally, run bun . to execute it.

  8. For the first run, hyperimport will automatically fetch and install the package hence it might take some time and when done, it will display the contents successfully.

  9. Now next time when bun . is ran, hyperimport will used the cached package and instantly print the contents of data.yml.

To reinstall packages, simply run bunx hyperimport i.

Clone this wiki locally