Building
Universal Plugin (Recommended)
unplugin-gem provides a unified plugin for all major bundlers.
Supports: Vite, Webpack, Rollup, esbuild, Rspack and Rolldown.
See unplugin-gem documentation for usage.
SWC Plugin
For direct SWC usage:
npm install swc-plugin-gempnpm install swc-plugin-gemConfig:
https://raw.githubusercontent.com/mantou132/gem/main/crates/swc-plugin-gem/src/lib.rs
#[derive(Deserialize, Debug, Clone, PartialEq, Default)]
#[serde(default, rename_all = "camelCase")]
struct PluginConfig {
/// Minify CSS in `css`/`styled` template literals
pub style_minify: bool,
/// Minify HTML in `html`/`svg`/`mathml` template literals
pub html_minify: bool,
/// e.g: https://github.com/mantou132/gem/blob/main/crates/swc-plugin-gem/README.md#example
pub auto_import: AutoImport,
/// Generate .d.ts file, use src/auto-import.d.ts when true
pub auto_import_dts: AutoImportDts,
/// Use esm directly with import map
pub resolve_path: bool,
/// Depend on URL loader & top await, only rewrite to `?url` in the server build
pub preload: bool,
/// Under development. `true` / `"webpack-hot"` emit `import.meta.webpackHot`;
/// `unplugin-gem` injects `@mantou/gem/helper/hmr` and passes the matching target.
/// Using this plugin directly still needs that helper on the entry.
pub hmr: HmrConfig,
/// Support `&:hover` in shadow dom and light dom
pub selector_compatible: bool,
/// SSR support: `"server"` / `"client"` build (`true` only adds keys, e.g. the build target is unknown),
/// add key to module level `createStore` to sync store values to the client,
/// rewrite `@server()` / `@lazy()` element classes in the client build,
/// rewrite `@client()` element modules in the server build,
/// `"lazy-chunk"` is set by `unplugin-gem` for the `?gem-lazy` module of the lazy view
pub ssr: SsrConfig,
/// un-implement
pub lazy_view: bool,
}