-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ddc0b1
commit effd2c0
Showing
9 changed files
with
151 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export { babelMacros } from "./babel-macros" | ||
export { transformer } from "./transformer" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { PluginOption } from "vite" | ||
import { lingui } from "@lingui/vite-plugin" | ||
import { linguiCoreMacros } from "./core-macros-plugin" | ||
import type { Api } from "@vitejs/plugin-vue" | ||
import { transformer } from "../compiler" | ||
|
||
type LinguiConfigOpts = { | ||
cwd?: string | ||
configPath?: string | ||
skipValidation?: boolean | ||
} | ||
|
||
type Options = { | ||
suppressRegisteringBabelMacro?: boolean | ||
linguiConfigOptions?: LinguiConfigOpts | ||
isProduction?: boolean | ||
} | ||
|
||
export function vueLingui(options: Options = {}): PluginOption[] { | ||
options = { | ||
suppressRegisteringBabelMacro: false, | ||
isProduction: process.env.NODE_ENV === "production", | ||
...options, | ||
} | ||
|
||
return [ | ||
lingui(options.linguiConfigOptions), | ||
!options.suppressRegisteringBabelMacro ? linguiCoreMacros() : false, | ||
{ | ||
name: "vite-plugin-lingui-vue-transform", | ||
enforce: "pre", | ||
configResolved(config) { | ||
const vitePlugin = config.plugins.find( | ||
(plugin) => plugin.name === "vite:vue" | ||
) | ||
|
||
if (!vitePlugin) { | ||
throw new Error( | ||
"Lingui Vue Plugin: Vite plugin is not found in your configuration. Please install it and to your Vite config" | ||
) | ||
} | ||
|
||
const api = vitePlugin.api as Api | ||
|
||
// register Lingui template transformer | ||
api.options.template = { | ||
...api.options.template, | ||
compilerOptions: { | ||
...api.options.template?.compilerOptions, | ||
nodeTransforms: [ | ||
transformer({ stripNonEssentialProps: options.isProduction }), | ||
...(api.options.template?.compilerOptions?.nodeTransforms || []), | ||
], | ||
}, | ||
} | ||
}, | ||
}, | ||
] | ||
} | ||
|
||
export default lingui |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters