Import from Gleam (*.gleam) files directly.
npm i vite-gleam- Create a basic Vite project (
npm create vite) - Create a
gleam.tomland 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 autocomplete 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. Create a
*.jsconfig(or*.tsconfigfor TypeScript). Add the following JSON and run the dev server. ReplacePROJECT_NAMEwith the name specified ingleam.toml.
{
"compilerOptions": {
"allowJs": true,
"rootDirs": ["./build/dev/javascript/PROJECT_NAME", "./src"],
"allowArbitraryExtensions": true
}
}