@weapp-stylex/weapp-vite

StyleX compiler integration for native and Wevu mini-programs and the weapp-vite Web runtime
959 2
Install
npm install @weapp-stylex/weapp-vite
Latest Version:0.4.1
License:MIT
Last Updated:Oct 23, 2026
Links: GitHub  ·  npm
Maintainer: icebreaker

@weapp-stylex/weapp-vite

将官方 StyleX 编译为原生小程序和 Wevu 的微信/支付宝/抖音样式及 H5 CSS。要求 weapp-vite >=7.4.0 <8。当前仓库示例使用 weapp-vite/Wevu 7.4.0;7.5.0 的开发宿主升级因 Linux 集成检查失败暂不接受,详情见依赖评估。

pnpm add @weapp-stylex/core
pnpm add -D @weapp-stylex/weapp-vite

原生 TS/JS 使用 stylexCompiler():

import { stylexCompiler } from '@weapp-stylex/weapp-vite'
import { defineConfig } from 'weapp-vite/config'

export default defineConfig({
  weapp: { srcRoot: 'src', compilerPlugins: [stylexCompiler()] },
})

Wevu SFC 注册同一工厂的两个字段,以共享编译 session:

import { createStylex } from '@weapp-stylex/weapp-vite'
import { defineConfig } from 'weapp-vite/config'

const stylex = createStylex()
export default defineConfig({
  plugins: stylex.vitePlugins,
  weapp: { srcRoot: 'src', compilerPlugins: [stylex.compilerPlugin] },
})

支持共享 styles.ts、条件合并、主题和动态 style。原生通过 data 绑定 attrs.class / attrs.style;Wevu 使用 computed 及显式 :class / :style。

完整示例与支持边界见 weapp-stylex。数值 16 输出 16px,rpx 需显式字符串。

MIT License。

构建使用 tsdown;本包保留 ESM-only 的 dist/index.js 与 dist/index.d.ts,编译器和宿主依赖保持 external。

Platforms

Native and Wevu hosts infer WeChat, Alipay, Douyin or Web from their active platform. Use both createStylex() fields for cross-platform builds and provide a Web index.html importing /@weapp-vite/web/entry. The Web runtime receives page/component CSS metadata, preserves page defaults and allows component theme inheritance through Shadow DOM. Numeric/px values keep official semantics; only static rpx follows the host policy. The upstream Web runtime is experimental; the example uses an equivalent SFC for the mini-program JSX fixture.

Related Packages

@weapp-stylex/uni-app

StyleX Vite plugin for uni-app Vue 3 targeting WeChat, Alipay, Douyin and H5

963 2
weapp-stylex

StyleX runtime and build adapters for WeChat, Alipay, Douyin and H5: native, Wev...

905 2
@weapp-stylex/taro

StyleX plugin for Taro React and Vue 3 targeting WeChat, Alipay, Douyin and H5 w...

1,026 2
@weapp-stylex/compiler

Shared StyleX compiler for WeChat, Alipay, Douyin and H5: JavaScript, TypeScript...

1,139 2
@weapp-vite/eslint

Wevu compatibility ESLint plugin and recommended configuration

34,024 516

Version History

Version Released License
0.4.1 MIT
0.4.0 MIT
0.3.0 MIT
0.2.1 MIT
0.2.0 MIT
Pre-releases (1)
Version Released License
0.0.0-stage