Import from Gleam (*.gleam
) files directly.
npm i vite-gleam
- Create a basic Vite project (
npm create vite
) - Create a
gleam.toml
and add Gleam dependencies - Update your vite config
// vite.config.{ts,js}
import gleam from "vite-gleam";
export default {
plugins: [gleam()],
};
- Start importing from Gleam!
By default, TypeScript (LSP) will complain about importing files with the .gleam
extension. There are two choices for fixes:
- If the type of the import doesnt matter , add
declare module "*.gleam";
inside any TypeScript file. A caveat is the LSP does not know if a export exists so it will not provide autocompletion when importing a Gleam file and it will type exports asany
. - Alternatively, if the vite dev server is running you can have full type safety when importing from Gleam.
npm i ts-gleam
. Create atsconfig.json
/jsconfig.json
and setcompilerOptions.plugins
to[{"name": "ts-gleam"}]
(RECOMMENDED)