There are three ways to invoke the Paraglide JS compiler:
- Via the Paraglide CLI
- Via a bundler plugin
- Programatically
Bundler plugins are the recommend approach. They are more flexible and can be integrated into your build pipeline.
To compile your messages via the CLI, run the following command:
npx @inlang/paraglide-js compile --project ./project.inlang --outdir ./src/paraglide
Use --help
to see all available options:
npx @inlang/paraglide-js compile --help
Paraglide JS exports bundler plugins via the paraglide<Bundler>Plugin()
functions.
paraglideRollupPlugin
paraglideWebpackPlugin
paraglideVitePlugin
paraglideRspackPlugin
paraglideRolldownPlugin
paraglideEsbuildPlugin
- ... and more plugins supported by unplugin
import { defineConfig } from "vite";
import { paraglideVitePlugin } from "@inlang/paraglide-js";
export default defineConfig({
plugins: [
paraglideVitePlugin({
project: "./project.inlang",
outdir: "./src/paraglide",
}),
],
});
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);