Compiling messages
There are three ways to invoke the Paraglide JS compiler:
- Via the Paraglide CLI
- Via a bundler plugin
- Programatically
Via the Paraglide CLI
To compile your messages via the CLI, run the following command:
npx @inlang/paraglide-js compile --project ./project.inlang --outdir ./src/paraglide
Via a bundler plugin
Paraglide JS exports bundler plugins via the paraglide<Bundler>Plugin()
functions.
paraglideRollupPlugin
paraglideWebpackPlugin
paraglideVitePlugin
- ... and more plugins supported by unplugin
Vite example
import { defineConfig } from "vite";
import { paraglideVitePlugin } from "@inlang/paraglide-js";
export default defineConfig({
plugins: [
paraglideVitePlugin({
project: "./project.inlang",
outdir: "./src/paraglide",
}),
],
});
Programatically
The Paraglide compiler can be invoked programatically via the compile
function.
import { compile } from "@inlang/paraglide-js";
await compile({
project: "./project.inlang",
outdir: "./src/paraglide",
});
If you need/want to extend the compiler, you can use the lower level compileProject
function.
import { compileProject } from "@inlang/paraglide-js";
import { loadProjectFromDirectory } from "@inlang/sdk";
const inlangProject = await loadProjectFromDirectory({
path: "./project.inlang",
})
const output = await compileProject({
project: inlangProject
});
console.log(output);