@amaster.ai/vite-plugins 1.1.0-beta.8 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,14 +1,9 @@
1
1
  import { Plugin } from 'vite';
2
2
 
3
- /**
4
- * Vite plugin: Add data-node-component-id to React components
5
- * Only enabled in development mode
6
- */
7
- declare function componentIdPlugin(): Plugin;
8
-
9
3
  /**
10
4
  * Vite plugin: Inject editor bridge script
11
- * Injects bridge.js in development mode by reading the built bridge script
5
+ * Injects minimal bridge that loads external script from platform
6
+ * Also provides virtual module for HMR and Tailwind config monitoring
12
7
  */
13
8
  declare function editorBridgePlugin(): Plugin;
14
9
 
@@ -20,30 +15,6 @@ declare function routesExposePlugin(options?: {
20
15
  routesFilePath?: string;
21
16
  }): Plugin;
22
17
 
23
- /**
24
- * Smart Reload 插件
25
- *
26
- * 在 Vite 服务器重启期间(如 PM2 重启 web-server),拦截浏览器端的刷新行为,
27
- * 让浏览器静默等待 WebSocket 重连,重连成功后不刷新页面(除非有实际的模块变更)。
28
- *
29
- * 场景说明:
30
- * - PM2 杀掉 Vite 进程 → WebSocket 断开 → PM2 重启 → 新 Vite 启动
31
- * - Vite 客户端检测到 WebSocket 断开后会通过 HTTP ping 轮询等待服务器恢复
32
- * - 服务器恢复后 Vite 客户端会调用 location.reload() 刷新页面
33
- * - 本插件拦截这个刷新行为,让页面保持当前状态
34
- *
35
- * 区分两种 full-reload 场景:
36
- * 1. 服务器重启 → full-reload 后 WebSocket 断开 → 静默等待重连,不刷新
37
- * 2. 模块变更需要 full-reload → WebSocket 保持连接 → 正常刷新
38
- *
39
- * 纯浏览器端方案,对用户完全无感:
40
- * - 不依赖服务端发送特殊消息
41
- * - WebSocket 断开 → 进入静默等待模式 → 抑制 location.reload
42
- * - Vite 客户端 HTTP ping 成功后调用 location.reload → 被拦截
43
- * - 拦截后延迟执行一次 soft-reload 恢复 HMR 连接
44
- */
45
- declare function smartReloadPlugin(): Plugin;
46
-
47
18
  interface TaroStyleAdapterOptions {
48
19
  /**
49
20
  * Design width for responsive scaling (default: 375)
@@ -208,32 +179,95 @@ interface PostCSSPlugin {
208
179
  }
209
180
  declare function rpx2pxPlugin(options?: Rpx2pxPluginOptions): PostCSSPlugin;
210
181
 
182
+ interface JsxInlineStyleRpxOptions {
183
+ /**
184
+ * rpx 到 px 的转换比例(默认 2)
185
+ * 即 2rpx = 1px(基于 375 设计稿)
186
+ */
187
+ ratio?: number;
188
+ }
189
+ declare function transformJsxInlineStyleRpx(code: string, ratio?: number): {
190
+ changed: boolean;
191
+ code: string;
192
+ };
193
+ declare function jsxInlineStyleRpxPlugin(options?: JsxInlineStyleRpxOptions): Plugin;
194
+
195
+ /**
196
+ * Vite plugin: JSX Source Tagger
197
+ * Intercepts react/jsx-dev-runtime to add source information to DOM elements
198
+ * Only enabled in development mode
199
+ */
200
+ declare function jsxSourceTaggerPlugin(): Plugin;
201
+
202
+ /**
203
+ * Vite plugin: Tailwind Config Sync
204
+ * Simplified version - just return raw config without resolveConfig
205
+ */
206
+ declare function tailwindConfigSyncPlugin(options?: {
207
+ configPath?: string;
208
+ }): Plugin;
209
+
211
210
  interface DevToolsOptions {
211
+ /**
212
+ * 是否为 Taro 项目
213
+ * - true: 启用 Taro 相关插件(taroStyleAdapterPlugin、rpx2pxPlugin)
214
+ * - false: 禁用 Taro 相关插件
215
+ * - undefined: 自动检测(通过 process.env.TARO_ENV 判断,默认为 false)
216
+ */
217
+ isTaro?: boolean;
212
218
  /**
213
219
  * Taro style adapter options
214
220
  * Controls H5 responsive scaling to match mini-program rpx behavior
221
+ * 仅在 isTaro 为 true 时生效
215
222
  */
216
223
  styleAdapter?: TaroStyleAdapterOptions;
224
+ /**
225
+ * 是否启用 JSX Source Tagger(通过 Symbol 标记元素源码位置)
226
+ * 默认:开发模式启用
227
+ */
228
+ jsxSourceTagger?: boolean;
229
+ /**
230
+ * 是否启用 Tailwind Config 同步(生成 JSON 文件)
231
+ * 默认:开发模式启用
232
+ */
233
+ tailwindConfigSync?: boolean;
234
+ /**
235
+ * Tailwind 配置文件路径
236
+ * 默认:./tailwind.config.ts
237
+ */
238
+ tailwindConfigPath?: string;
217
239
  }
218
240
  /**
219
241
  * 开发工具插件集合,简化调用,vite.config.ts 直接 devTools() 即可
242
+ *
220
243
  * @param options 配置项
244
+ * @param options.isTaro 是否为 Taro 项目(默认根据 TARO_ENV 自动判断)
221
245
  * @param options.styleAdapter Taro H5 样式适配配置,designWidth 应与 Taro config 一致
222
246
  * @returns Plugin[] Vite 插件数组
223
247
  *
224
248
  * @example
225
249
  * ```ts
226
- * // config/dev.ts
250
+ * // Taro 项目 - config/dev.ts
227
251
  * import devTools from "@amaster.ai/vite-plugins";
228
252
  *
229
253
  * export default {
230
254
  * compiler: {
231
255
  * type: 'vite',
232
- * vitePlugins: [devTools()]
256
+ * vitePlugins: [devTools({ isTaro: true })]
233
257
  * }
234
258
  * }
235
259
  * ```
260
+ *
261
+ * @example
262
+ * ```ts
263
+ * // React 项目 - vite.config.ts
264
+ * import devTools from "@amaster.ai/vite-plugins";
265
+ *
266
+ * export default {
267
+ * plugins: [devTools()] // isTaro 默认为 false
268
+ * }
269
+ * ```
236
270
  */
237
271
  declare function devTools(options?: DevToolsOptions): Plugin[];
238
272
 
239
- export { type DevToolsOptions, type Rpx2pxPluginOptions, type TaroStyleAdapterOptions, componentIdPlugin, devTools as default, editorBridgePlugin, injectAmasterEnv, injectTaroEnv, routesExposePlugin, rpx2pxPlugin, smartReloadPlugin, taroStyleAdapterPlugin };
273
+ export { type DevToolsOptions, type Rpx2pxPluginOptions, type TaroStyleAdapterOptions, devTools as default, editorBridgePlugin, injectAmasterEnv, injectTaroEnv, jsxInlineStyleRpxPlugin, jsxSourceTaggerPlugin, routesExposePlugin, rpx2pxPlugin, tailwindConfigSyncPlugin, taroStyleAdapterPlugin, transformJsxInlineStyleRpx };