构建

通用插件(推荐)

unplugin-gem 为所有主流构建工具提供统一的插件。

支持:Vite、Webpack、Rollup、esbuild、Rspack 和 Rolldown。

使用方法请参考 unplugin-gem 文档。

SWC 插件

直接使用 SWC 时:

npm install swc-plugin-gem
pnpm install swc-plugin-gem

配置:

#[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,
}