@lingui/vite-plugin
Version:
Vite plugin to integrate Lingui message catalogs with the CLI and bundler pipeline
70 lines (62 loc) • 2.52 kB
text/typescript
import { Plugin } from 'vite';
import * as pluginBabel from '@rolldown/plugin-babel';
import * as babelPluginLinguiMacro from '@lingui/babel-plugin-lingui-macro';
/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-ignore --- `@rolldown/plugin-babel` is an optional peer dependency, so this may cause an error
type RolldownBabelPreset = pluginBabel.RolldownBabelPreset
// @ts-ignore --- `babel-plugin-react-compiler` is an optional peer dependency, so this may cause an error
type LinguiMacroBabelPluginOptions =
babelPluginLinguiMacro.LinguiPluginOpts
/**
* Convenient helper to define a rolldown preset with Lingui Transformer for `@rolldown/plugin-babel`
*
* @example
* ```js
* // vite.config.js
* import { defineConfig } from 'vite'
* import react from '@vitejs/plugin-react'
* import babel from '@rolldown/plugin-babel'
* import { lingui, linguiTransformerBabelPreset } from '@lingui/vite-plugin'
*
* export default defineConfig({
* plugins: [react(), lingui(), babel({ presets: [linguiTransformerBabelPreset()] })],
* })
* ```
* @param options Options Passed to the babel-plugin-lingui-macro
* @param linguiConfigConfigOpts options passed to the lingui config discovery function
*
*
* > [!TIP]
* >
* > `linguiTransformerBabelPreset` is only a convenient helper with a preconfigured filter. You can configure override the filters to fit your project structure or code. For example, if you know a large portion of your files are never Lingui-related, you can aggressively exclude them via `rolldown.filter`:
* >
* > ```js
* > const myPreset = linguiTransformerBabelPreset()
* > myPreset.rolldown.filter.id.exclude = ['src/legacy/**', 'src/utils/**']
* >
* > babel({
* > presets: [myPreset],
* > })
* > ```
*/
declare const linguiTransformerBabelPreset: (options?: LinguiMacroBabelPluginOptions, linguiConfigConfigOpts?: {
cwd?: string;
configPath?: string;
skipValidation?: boolean;
}) => RolldownBabelPreset;
type LinguiPluginOpts = {
cwd?: string;
configPath?: string;
skipValidation?: boolean;
/**
* If true would fail compilation on missing translations
**/
failOnMissing?: boolean;
/**
* If true would fail compilation on message compilation errors
**/
failOnCompileError?: boolean;
};
declare function lingui({ failOnMissing, failOnCompileError, ...linguiConfig }?: LinguiPluginOpts): Plugin[];
export { lingui as default, lingui, linguiTransformerBabelPreset };
export type { LinguiPluginOpts };