@fluixi/compiler

中文文档
1.0.0-alpha.108发布于 2026/11/07MITTypeScriptESM + CJS近 30 天下载 3990

compiles JSX and html`` templates to direct DOM calls via shared IR; Babel is used as parser only

原始使用文档
文档目录7 节
  1. ✨ Overview
  2. What it does to your code
  3. 📦 Installation
  4. 🚀 Usage
  5. Compiling through Babel
  6. 🔌 Subpaths
  7. 📄 License

Fluixi

@fluixi/compiler

The Fluixi compiler: parses, lowers and emits. Not a Babel plugin.

License: MIT TypeScript npm


✨ Overview

@fluixi/compiler turns Fluixi source into fine-grained reactive output. Both authoring syntaxes, JSX and html`...` templates, lower to the same host-agnostic IR, and the imperative backend compiles that straight into @fluixi/dom runtime calls (createNativeElement/spread/insert/createComponent/...). No VDOM, and no jsx() dispatch at runtime.

It owns the transform rather than running inside someone else's: parse once, splice the emitted code over the spans it replaces. Nothing is reprinted, so a hole keeps the text the author wrote and every edit carries a source map; types are left in place for the bundler to strip.

@babel/parser is the only package it takes from that namespace, used as a parser: the same position Vue's compiler is in. @babel/core and the plugin machinery are optional peers, needed only by babel: true.

The @fluixi/jsx automatic runtime is still what esbuild and TypeScript's jsxImportSource point at; this compiler simply never emits a call into it.

It also provides the "use server" transform (server functions): the client build gets an RPC stub, the server build keeps and registers the body.

Most apps don't use this package directly: @fluixi/vite-plugin (and @fluixi/start) wrap it.

What it does to your code

Beyond turning markup into DOM calls:

Props you destructured stay reactive. function Card({ title }) compiles to props.title at each use, so the binding keeps updating, and ...rest becomes the splitProps call you would have written. Anything it can't prove safe: a reassigned binding, a computed key, a default it would have to re-run per read: is left exactly as written and reported. On by default; set propsDestructure: false for a package that ships its source for consumers to compile, since the rewrite belongs to whoever compiles.

$ intrinsics resolve without an import. $signal, $memo, $effect, $store, $resource, $selector, $deferred, $untrack, $untrackStore compile to the runtime calls they stand for, and the import is added for what a module actually used. A primitive is recognised by the binding it came from, never by name: import { signal as state } is recognised, a local function signal() is not. A module that binds a $ name keeps its own meaning and gets a diagnostic.

Unimported tags resolve through rules. resolve says where a capitalised tag comes from: an entry per component, or one pattern for a family:

createVitePlugin({ resolve: [{ match: /^([A-Z]\w+)$/, module: '/src/components/$1.tsx' }] })

load: splits a component into its own chunk. load:visible, load:idle, load:interaction, load:media decide when its module is fetched. It works on a component a rule supplies and on one you imported yourself: in the second case the static import is removed, which only happens when the name is used nowhere but as a tag.

It says when it couldn't do these things. A tag nothing supplies and a load: that can't apply both build cleanly and fail at runtime, so they're reported at build time with the reason. The bundler adapters print them; TransformResult carries them as propsDiagnostics, intrinsicDiagnostics, loadDiagnostics and unresolvedDiagnostics if you're driving the transform yourself.

📦 Installation

pnpm add -D @fluixi/compiler

🚀 Usage

Via the Vite integration (the common path):

import { defineConfig } from 'vite';
import { createVitePlugin, serverFunctionsVitePlugin } from '@fluixi/compiler/integrations';

export default defineConfig({
  plugins: [
    serverFunctionsVitePlugin(),          // "use server" transform
    createVitePlugin(),
  ],
});

Or compile a module directly:

import { transformTemplates } from '@fluixi/compiler/transform';

const { code, map } = transformTemplates(source, 'App.tsx', {})!;

transformTemplates returns null when there is nothing to do: no JSX, no templates, no $ intrinsics and nothing to report: so a bundler can leave the file untouched.

Compiling through Babel

fluixi({ babel: true }) routes through the Babel front-end instead. It exists for a project whose own Babel plugins have to see the compiled output; it needs @babel/core and friends installed, and says so rather than degrading. Everything else: the IR, the passes, the backend: is the same code either way.

🔌 Subpaths

ImportWhatBabel
@fluixi/compilerIR, codegen backends, resolve/optimize passes, optionsnone
@fluixi/compiler/builtinsthe control-flow / router component namesnone
@fluixi/compiler/transformtransformTemplates, transformServerFnsparser only
@fluixi/compiler/integrationsvite, webpack, rollup and esbuild adaptersparser only
@fluixi/compiler/babelthe Babel plugin front-end@babel/core

no-babel-in-core.spec.ts fails the build if that column stops being true.

📄 License

MIT © Fluixi

版本与发布记录

@fluixi/compiler 共发布 56 个版本,首次发布于 2026/07/10;过去 12 个月发布了 56 个版本。

版本发布日期距今
1.0.0-alpha.108latest2026/11/078 天前
1.0.0-alpha.1072026/11/0511 天前
1.0.0-alpha.1062026/11/0213 天前
1.0.0-alpha.1052026/11/0115 天前
1.0.0-alpha.1042026/11/0115 天前
1.0.0-alpha.1032026/10/2620 天前

关于 @fluixi/compiler 的常见问题

@fluixi/compiler 是什么?

compiles JSX and html`` templates to direct DOM calls via shared IR; Babel is used as parser only

如何安装 @fluixi/compiler?

在项目目录运行 npm install @fluixi/compiler,或使用 pnpm add / yarn add / bun add。

@fluixi/compiler 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@fluixi/compiler 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@fluixi/compiler 可以商用吗?

@fluixi/compiler 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@fluixi/compiler 的下载量有多少?

根据 npm 官方下载统计,@fluixi/compiler 在 2026/10/15 – 2026/11/13 这 30 天内被下载 3,990 次,日均约 133 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@fluixi/compiler 还在维护吗?

最新版本 1.0.0-alpha.108 发布于 2026/11/07(8 天前);至今共发布 56 个版本,其中过去 12 个月发布了 56 个;首次发布于 2026/07/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。