tona-vite 1.0.21 → 1.0.22

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/README.md CHANGED
@@ -1,38 +1,68 @@
1
- # vite-plugin-tona
1
+ # tona-vite
2
2
 
3
- Vite plugin for Tona themes - combines dynamic script extension and shared assets serving.
3
+ <p align="center">
4
+ <img src="../../assets/tona.png" alt="Tona" width="100" />
5
+ </p>
6
+
7
+ <p align="center">
8
+ Vite plugin for Tona theme development.
9
+ </p>
10
+
11
+ <p align="center">
12
+ <a href="https://www.npmjs.com/package/tona-vite"><img src="https://img.shields.io/npm/v/tona-vite?style=flat-square" alt="npm version"></a>
13
+ <a href="LICENSE"><img src="https://img.shields.io/npm/l/tona-vite?style=flat-square" alt="license"></a>
14
+ <a href="https://vitejs.dev"><img src="https://img.shields.io/badge/Vite-^5.0.0-646CFF?style=flat-square&logo=vite" alt="Vite"></a>
15
+ </p>
16
+
17
+ **English** | [中文](./README.zh-CN.md)
18
+
19
+ ## Features
20
+
21
+ - **Dynamic Script Injection** - Automatically detects and injects theme scripts
22
+ - **Shared Assets Serving** - Serves shared assets during development
23
+ - **IIFE Build Output** - Configures library format for theme distribution
24
+ - **Dev Server Support** - Full development server with hot reload
25
+ - **Multiple Asset Paths** - Supports `/public/`, `/templates/`, `/js/`, `/css/`, `/images/`
4
26
 
5
27
  ## Installation
6
28
 
7
29
  ```bash
8
- npm install tona-vite
30
+ npm install -D tona-vite
31
+ ```
32
+
33
+ ```bash
34
+ pnpm add -D tona-vite
9
35
  ```
10
36
 
11
37
  ## Usage
12
38
 
13
- ```ts
39
+ ```typescript
14
40
  import tona from 'tona-vite'
15
- import { defineConfig } from 'vite'
41
+ import { defineConfig } from 'vite-plus'
16
42
 
17
43
  export default defineConfig({
18
- plugins: [
19
- tona()
20
- ]
44
+ plugins: [tona()],
21
45
  })
22
46
  ```
23
47
 
24
- ## Features
48
+ ### With Options
25
49
 
26
- - Automatically detects `main.ts` or `main.js` files and replaces script src in HTML
27
- - Configures Vite build as IIFE library format for theme distribution
28
- - Serves shared assets from public directory during development
29
- - Supports multiple asset paths: `/public/`, `/templates/`, `/js/`, `/css/`, `/images/`
30
- - Automatically sets correct MIME types for served files
31
- - Works in both development and build modes
50
+ ```typescript
51
+ import tona from 'tona-vite'
52
+ import { defineConfig } from 'vite-plus'
53
+
54
+ export default defineConfig({
55
+ plugins: [
56
+ tona({
57
+ themeName: 'my-theme',
58
+ }),
59
+ ],
60
+ })
61
+ ```
32
62
 
33
63
  ## Options
34
64
 
35
- ```ts
65
+ ```typescript
36
66
  interface TonaPluginOptions {
37
67
  /**
38
68
  * Theme name for build output filename
@@ -44,12 +74,14 @@ interface TonaPluginOptions {
44
74
 
45
75
  ## Build Configuration
46
76
 
47
- The plugin automatically configures Vite's build mode:
77
+ The plugin automatically configures Vite for theme development:
48
78
 
49
- - **Library format**: IIFE (Immediately Invoked Function Expression)
50
- - **Entry point**: Automatically detects `src/main.ts` or `src/main.js`
51
- - **Output filename**: `{themeName}.min.js` (default: `theme.min.js`)
52
- - **CSS code splitting**: Disabled (all styles bundled together)
79
+ | Setting | Value | Description |
80
+ | ------------------ | ------------------------------ | --------------------------------------- |
81
+ | Library Format | IIFE | Immediately Invoked Function Expression |
82
+ | Entry Point | `src/main.ts` or `src/main.js` | Auto-detected |
83
+ | Output Filename | `{themeName}.min.js` | Default: `theme.min.js` |
84
+ | CSS Code Splitting | Disabled | All styles bundled together |
53
85
 
54
86
  ## Development Server
55
87
 
@@ -61,3 +93,31 @@ During development, the plugin serves static assets from the plugin's public dir
61
93
  - `/css/*` - CSS files
62
94
  - `/images/*` - Image files
63
95
  - `/` or `/index.html` - Navigation index page
96
+
97
+ ## Example Project Structure
98
+
99
+ ```
100
+ my-theme/
101
+ ├── src/
102
+ │ ├── main.ts # Theme entry
103
+ │ └── style.css # Theme styles
104
+ ├── vite.config.ts # Vite + Tona plugin config
105
+ └── package.json
106
+ ```
107
+
108
+ ## vite.config.ts Example
109
+
110
+ ```typescript
111
+ import tona from 'tona-vite'
112
+ import { defineConfig } from 'vite-plus'
113
+
114
+ export default defineConfig({
115
+ plugins: [tona()],
116
+ // Additional Vite config if needed
117
+ })
118
+ ```
119
+
120
+ ## Related
121
+
122
+ - [tona](https://github.com/guangzan/tona/tree/main/packages/core) - Core framework
123
+ - [create-tona](https://github.com/guangzan/tona/tree/main/packages/create-tona) - Project scaffolding
@@ -0,0 +1,123 @@
1
+ # tona-vite
2
+
3
+ <p align="center">
4
+ <img src="../../assets/tona.png" alt="Tona" width="100" />
5
+ </p>
6
+
7
+ <p align="center">
8
+ 用于 Tona 主题开发的 Vite 插件。
9
+ </p>
10
+
11
+ <p align="center">
12
+ <a href="https://www.npmjs.com/package/tona-vite"><img src="https://img.shields.io/npm/v/tona-vite?style=flat-square" alt="npm version"></a>
13
+ <a href="LICENSE"><img src="https://img.shields.io/npm/l/tona-vite?style=flat-square" alt="license"></a>
14
+ <a href="https://vitejs.dev"><img src="https://img.shields.io/badge/Vite-^5.0.0-646CFF?style=flat-square&logo=vite" alt="Vite"></a>
15
+ </p>
16
+
17
+ [English](./README.md) | **中文**
18
+
19
+ ## 特性
20
+
21
+ - **动态脚本注入** - 自动检测并注入主题脚本
22
+ - **共享资源服务** - 在开发期间提供共享资源
23
+ - **IIFE 构建输出** - 为主题分发配置库格式
24
+ - **开发服务器支持** - 完整的开发服务器和热重载
25
+ - **多资源路径** - 支持 `/public/`、`/templates/`、`/js/`、`/css/`、`/images/`
26
+
27
+ ## 安装
28
+
29
+ ```bash
30
+ npm install -D tona-vite
31
+ ```
32
+
33
+ ```bash
34
+ pnpm add -D tona-vite
35
+ ```
36
+
37
+ ## 使用
38
+
39
+ ```typescript
40
+ import tona from 'tona-vite'
41
+ import { defineConfig } from 'vite-plus'
42
+
43
+ export default defineConfig({
44
+ plugins: [tona()],
45
+ })
46
+ ```
47
+
48
+ ### 使用选项
49
+
50
+ ```typescript
51
+ import tona from 'tona-vite'
52
+ import { defineConfig } from 'vite-plus'
53
+
54
+ export default defineConfig({
55
+ plugins: [
56
+ tona({
57
+ themeName: 'my-theme',
58
+ }),
59
+ ],
60
+ })
61
+ ```
62
+
63
+ ## 选项
64
+
65
+ ```typescript
66
+ interface TonaPluginOptions {
67
+ /**
68
+ * 构建输出文件名的主题名称
69
+ * @default 'theme'
70
+ */
71
+ themeName?: string
72
+ }
73
+ ```
74
+
75
+ ## 构建配置
76
+
77
+ 该插件自动配置 Vite 用于主题开发:
78
+
79
+ | 设置 | 值 | 描述 |
80
+ | ------------ | ------------------------------ | -------------------- |
81
+ | 库格式 | IIFE | 立即执行函数表达式 |
82
+ | 入口点 | `src/main.ts` 或 `src/main.js` | 自动检测 |
83
+ | 输出文件名 | `{themeName}.min.js` | 默认:`theme.min.js` |
84
+ | CSS 代码分割 | 禁用 | 所有样式打包在一起 |
85
+
86
+ ## 开发服务器
87
+
88
+ 在开发期间,该插件从插件的 public 目录提供静态资源:
89
+
90
+ - `/public/*` - 通用公共资源
91
+ - `/templates/*` - HTML 模板
92
+ - `/js/*` - JavaScript 文件
93
+ - `/css/*` - CSS 文件
94
+ - `/images/*` - 图片文件
95
+ - `/` 或 `/index.html` - 导航索引页面
96
+
97
+ ## 示例项目结构
98
+
99
+ ```
100
+ my-theme/
101
+ ├── src/
102
+ │ ├── main.ts # 主题入口
103
+ │ └── style.css # 主题样式
104
+ ├── vite.config.ts # Vite + Tona 插件配置
105
+ └── package.json
106
+ ```
107
+
108
+ ## vite.config.ts 示例
109
+
110
+ ```typescript
111
+ import tona from 'tona-vite'
112
+ import { defineConfig } from 'vite-plus'
113
+
114
+ export default defineConfig({
115
+ plugins: [tona()],
116
+ // 如有需要,可添加额外的 Vite 配置
117
+ })
118
+ ```
119
+
120
+ ## 相关
121
+
122
+ - [tona](https://github.com/guangzan/tona/tree/main/packages/core) - 核心框架
123
+ - [create-tona](https://github.com/guangzan/tona/tree/main/packages/create-tona) - 项目脚手架
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;UAYiB,iBAAA;;AAAjB;AAMC;;;;;;;iBAKuB,IAAA,WAAc,oBAAyB"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;UAYiB,iBAAA;;AAAjB;;;EAKE,SAAA;AAAA;AACD;;;AAAA,iBAKuB,IAAA,CAAK,OAAA,GAAS,iBAAA,GAAyB,MAAA"}
package/dist/index.mjs CHANGED
@@ -2,7 +2,6 @@ import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import process from "node:process";
4
4
  import { fileURLToPath } from "node:url";
5
-
6
5
  //#region src/index.ts
7
6
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
8
7
  /**
@@ -36,14 +35,13 @@ function tona(options = {}) {
36
35
  fileName: () => `${themeName}.min.js`,
37
36
  cssFileName: `${themeName}.min`
38
37
  };
39
- return {
40
- ...config,
41
- build: {
42
- ...config.build,
43
- cssCodeSplit: config.build?.cssCodeSplit ?? false,
44
- lib: libConfig
45
- }
46
- };
38
+ const buildConfig = config.build ?? {};
39
+ const bundlerOptions = buildConfig.rolldownOptions ?? buildConfig.rollupOptions;
40
+ return { build: {
41
+ cssCodeSplit: buildConfig.cssCodeSplit ?? false,
42
+ lib: libConfig,
43
+ ...bundlerOptions ? { rolldownOptions: bundlerOptions } : {}
44
+ } };
47
45
  },
48
46
  transformIndexHtml(html) {
49
47
  const jsPath = path.resolve(baseDir, "src/main.js");
@@ -95,7 +93,7 @@ function tona(options = {}) {
95
93
  }
96
94
  };
97
95
  }
98
-
99
96
  //#endregion
100
97
  export { tona as default };
98
+
101
99
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["resolvedEntryPath: string | null","filePath: string | null"],"sources":["../src/index.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { fileURLToPath } from 'node:url'\nimport type { LibraryFormats, Plugin, UserConfig, ViteDevServer } from 'vite'\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url))\n\ninterface MimeTypes {\n [key: string]: string\n}\n\nexport interface TonaPluginOptions {\n /**\n * Theme name for build output filename\n * @default 'theme'\n */\n themeName?: string\n}\n\n/**\n * Vite plugin for Tona themes - combines dynamic script extension and shared assets serving\n */\nexport default function tona(options: TonaPluginOptions = {}): Plugin {\n const { themeName = 'theme' } = options\n\n // Default path to shared assets\n const assetsPath = path.join(__dirname, '..', 'public')\n const baseDir = process.cwd()\n\n return {\n name: 'vite-plugin-tona',\n\n config(config: UserConfig): UserConfig {\n // Check main.ts first, then main.js\n const tsPath = path.resolve(baseDir, 'src/main.ts')\n const jsPath = path.resolve(baseDir, 'src/main.js')\n\n let resolvedEntryPath: string | null = null\n if (fs.existsSync(tsPath)) {\n resolvedEntryPath = tsPath\n } else if (fs.existsSync(jsPath)) {\n resolvedEntryPath = jsPath\n }\n\n if (!resolvedEntryPath) {\n return config\n }\n\n const existingLib = config.build?.lib\n const libConfig =\n existingLib && typeof existingLib === 'object'\n ? {\n ...existingLib,\n formats: existingLib.formats || (['iife'] as LibraryFormats[]),\n entry: existingLib.entry || resolvedEntryPath,\n name: existingLib.name || themeName,\n fileName: existingLib.fileName || (() => `${themeName}.min.js`),\n cssFileName: existingLib.cssFileName || `${themeName}.min`, // 不能包含 .css 后缀,会自动生成,否则变成 .css.css\n }\n : {\n formats: ['iife'] as LibraryFormats[],\n entry: resolvedEntryPath,\n name: themeName,\n fileName: () => `${themeName}.min.js`,\n cssFileName: `${themeName}.min`, // 不能包含 .css 后缀,会自动生成,否则变成 .css.css\n }\n\n return {\n ...config,\n build: {\n ...config.build,\n cssCodeSplit: config.build?.cssCodeSplit ?? false,\n lib: libConfig,\n },\n }\n },\n\n transformIndexHtml(html) {\n // Check main.ts or main.js exists\n const jsPath = path.resolve(baseDir, 'src/main.js')\n const tsPath = path.resolve(baseDir, 'src/main.ts')\n let scriptSrc = '/src/main.js'\n\n if (fs.existsSync(tsPath)) {\n scriptSrc = '/src/main.ts'\n } else if (fs.existsSync(jsPath)) {\n scriptSrc = '/src/main.js'\n }\n\n // Replace script src in HTML\n return html.replace(\n /<script type=\"module\" src=\"[^\"]*\"><\\/script>/,\n `<script type=\"module\" src=\"${scriptSrc}\"></script>`,\n )\n },\n\n configureServer(server: ViteDevServer) {\n // Serve static files from shared-assets/public directory\n server.middlewares.use((req, res, next) => {\n let filePath: string | null = null\n\n // Check if the request is for a file in /public (which will be served from shared-assets)\n if (req.url?.startsWith('/public/')) {\n const urlWithoutQuery = req.url.split('?')[0]\n filePath = path.join(\n assetsPath,\n urlWithoutQuery!.replace('/public/', ''),\n )\n } else if (req.url?.startsWith('/templates/')) {\n const urlWithoutQuery = req.url.split('?')[0]\n filePath = path.join(\n assetsPath,\n 'templates',\n urlWithoutQuery!.replace('/templates/', ''),\n )\n } else if (req.url?.startsWith('/js/')) {\n const urlWithoutQuery = req.url.split('?')[0]\n filePath = path.join(\n assetsPath,\n 'js',\n urlWithoutQuery!.replace('/js/', ''),\n )\n } else if (req.url?.startsWith('/css/')) {\n const urlWithoutQuery = req.url.split('?')[0]\n filePath = path.join(\n assetsPath,\n 'css',\n urlWithoutQuery!.replace('/css/', ''),\n )\n } else if (req.url?.startsWith('/images/')) {\n const urlWithoutQuery = req.url.split('?')[0]\n filePath = path.join(\n assetsPath,\n 'images',\n urlWithoutQuery!.replace('/images/', ''),\n )\n } else if (\n req.url === '/' ||\n req.url?.startsWith('/?') ||\n req.url === '/index.html' ||\n req.url?.startsWith('/index.html?')\n ) {\n filePath = path.join(assetsPath, 'index.html')\n }\n\n // Check if file exists\n if (filePath && fs.existsSync(filePath)) {\n // Set appropriate content type\n const ext = path.extname(filePath).toLowerCase()\n const mimeTypes: MimeTypes = {\n '.html': 'text/html',\n '.css': 'text/css',\n '.js': 'application/javascript',\n '.json': 'application/json',\n '.png': 'image/png',\n '.jpg': 'image/jpeg',\n '.jpeg': 'image/jpeg',\n '.gif': 'image/gif',\n '.svg': 'image/svg+xml',\n '.ico': 'image/x-icon',\n }\n\n const contentType = mimeTypes[ext] || 'application/octet-stream'\n res.setHeader('Content-Type', contentType)\n\n // Read and serve the file\n const fileStream = fs.createReadStream(filePath)\n fileStream.pipe(res)\n return\n }\n\n // If not handled, pass to next middleware\n next()\n })\n },\n }\n}\n"],"mappings":";;;;;;AAMA,MAAM,YAAY,KAAK,QAAQ,cAAc,OAAO,KAAK,IAAI,CAAC;;;;AAiB9D,SAAwB,KAAK,UAA6B,EAAE,EAAU;CACpE,MAAM,EAAE,YAAY,YAAY;CAGhC,MAAM,aAAa,KAAK,KAAK,WAAW,MAAM,SAAS;CACvD,MAAM,UAAU,QAAQ,KAAK;AAE7B,QAAO;EACL,MAAM;EAEN,OAAO,QAAgC;GAErC,MAAM,SAAS,KAAK,QAAQ,SAAS,cAAc;GACnD,MAAM,SAAS,KAAK,QAAQ,SAAS,cAAc;GAEnD,IAAIA,oBAAmC;AACvC,OAAI,GAAG,WAAW,OAAO,CACvB,qBAAoB;YACX,GAAG,WAAW,OAAO,CAC9B,qBAAoB;AAGtB,OAAI,CAAC,kBACH,QAAO;GAGT,MAAM,cAAc,OAAO,OAAO;GAClC,MAAM,YACJ,eAAe,OAAO,gBAAgB,WAClC;IACE,GAAG;IACH,SAAS,YAAY,WAAY,CAAC,OAAO;IACzC,OAAO,YAAY,SAAS;IAC5B,MAAM,YAAY,QAAQ;IAC1B,UAAU,YAAY,mBAAmB,GAAG,UAAU;IACtD,aAAa,YAAY,eAAe,GAAG,UAAU;IACtD,GACD;IACE,SAAS,CAAC,OAAO;IACjB,OAAO;IACP,MAAM;IACN,gBAAgB,GAAG,UAAU;IAC7B,aAAa,GAAG,UAAU;IAC3B;AAEP,UAAO;IACL,GAAG;IACH,OAAO;KACL,GAAG,OAAO;KACV,cAAc,OAAO,OAAO,gBAAgB;KAC5C,KAAK;KACN;IACF;;EAGH,mBAAmB,MAAM;GAEvB,MAAM,SAAS,KAAK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Y,GAAG,WAAW,SAAS,EAAE;KAEvC,MAAM,MAAM,KAAK,QAAQ,SAAS,CAAC,aAAa;KAchD,MAAM,cAbuB;MAC3B,SAAS;MACT,QAAQ;MACR,OAAO;MACP,SAAS;MACT,QAAQ;MACR,QAAQ;MACR,SAAS;MACT,QAAQ;MACR,QAAQ;MACR,QAAQ;MACT,CAE6B,QAAQ;AACtC,SAAI,UAAU,gBAAgB,YAAY;AAI1C,KADmB,GAAG,iBAAiB,SAAS,CACrC,KAAK,IAAI;AACpB;;AAIF,UAAM;KACN;;EAEL"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { fileURLToPath } from 'node:url'\nimport type { LibraryFormats, Plugin, UserConfig, ViteDevServer } from 'vite'\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url))\n\ninterface MimeTypes {\n [key: string]: string\n}\n\nexport interface TonaPluginOptions {\n /**\n * Theme name for build output filename\n * @default 'theme'\n */\n themeName?: string\n}\n\n/**\n * Vite plugin for Tona themes - combines dynamic script extension and shared assets serving\n */\nexport default function tona(options: TonaPluginOptions = {}): Plugin {\n const { themeName = 'theme' } = options\n\n // Default path to shared assets\n const assetsPath = path.join(__dirname, '..', 'public')\n const baseDir = process.cwd()\n\n return {\n name: 'vite-plugin-tona',\n\n config(config: UserConfig): UserConfig {\n // Check main.ts first, then main.js\n const tsPath = path.resolve(baseDir, 'src/main.ts')\n const jsPath = path.resolve(baseDir, 'src/main.js')\n\n let resolvedEntryPath: string | null = null\n if (fs.existsSync(tsPath)) {\n resolvedEntryPath = tsPath\n } else if (fs.existsSync(jsPath)) {\n resolvedEntryPath = jsPath\n }\n\n if (!resolvedEntryPath) {\n return config\n }\n\n const existingLib = config.build?.lib\n const libConfig =\n existingLib && typeof existingLib === 'object'\n ? {\n ...existingLib,\n formats: existingLib.formats || (['iife'] as LibraryFormats[]),\n entry: existingLib.entry || resolvedEntryPath,\n name: existingLib.name || themeName,\n fileName: existingLib.fileName || (() => `${themeName}.min.js`),\n cssFileName: existingLib.cssFileName || `${themeName}.min`,\n }\n : {\n formats: ['iife'] as LibraryFormats[],\n entry: resolvedEntryPath,\n name: themeName,\n fileName: () => `${themeName}.min.js`,\n cssFileName: `${themeName}.min`,\n }\n\n const buildConfig = config.build ?? {}\n const bundlerOptions =\n buildConfig.rolldownOptions ?? buildConfig.rollupOptions\n\n return {\n build: {\n cssCodeSplit: buildConfig.cssCodeSplit ?? false,\n lib: libConfig,\n ...(bundlerOptions ? { rolldownOptions: bundlerOptions } : {}),\n },\n }\n },\n\n transformIndexHtml(html) {\n // Check main.ts or main.js exists\n const jsPath = path.resolve(baseDir, 'src/main.js')\n const tsPath = path.resolve(baseDir, 'src/main.ts')\n let scriptSrc = '/src/main.js'\n\n if (fs.existsSync(tsPath)) {\n scriptSrc = '/src/main.ts'\n } else if (fs.existsSync(jsPath)) {\n scriptSrc = '/src/main.js'\n }\n\n // Replace script src in HTML\n return html.replace(\n /<script type=\"module\" src=\"[^\"]*\"><\\/script>/,\n `<script type=\"module\" src=\"${scriptSrc}\"></script>`,\n )\n },\n\n configureServer(server: ViteDevServer) {\n // Serve static files from shared-assets/public directory\n server.middlewares.use((req, res, next) => {\n let filePath: string | null = null\n\n // Check if the request is for a file in /public (which will be served from shared-assets)\n if (req.url?.startsWith('/public/')) {\n const urlWithoutQuery = req.url.split('?')[0]\n filePath = path.join(\n assetsPath,\n urlWithoutQuery!.replace('/public/', ''),\n )\n } else if (req.url?.startsWith('/templates/')) {\n const urlWithoutQuery = req.url.split('?')[0]\n filePath = path.join(\n assetsPath,\n 'templates',\n urlWithoutQuery!.replace('/templates/', ''),\n )\n } else if (req.url?.startsWith('/js/')) {\n const urlWithoutQuery = req.url.split('?')[0]\n filePath = path.join(\n assetsPath,\n 'js',\n urlWithoutQuery!.replace('/js/', ''),\n )\n } else if (req.url?.startsWith('/css/')) {\n const urlWithoutQuery = req.url.split('?')[0]\n filePath = path.join(\n assetsPath,\n 'css',\n urlWithoutQuery!.replace('/css/', ''),\n )\n } else if (req.url?.startsWith('/images/')) {\n const urlWithoutQuery = req.url.split('?')[0]\n filePath = path.join(\n assetsPath,\n 'images',\n urlWithoutQuery!.replace('/images/', ''),\n )\n } else if (\n req.url === '/' ||\n req.url?.startsWith('/?') ||\n req.url === '/index.html' ||\n req.url?.startsWith('/index.html?')\n ) {\n filePath = path.join(assetsPath, 'index.html')\n }\n\n // Check if file exists\n if (filePath && fs.existsSync(filePath)) {\n // Set appropriate content type\n const ext = path.extname(filePath).toLowerCase()\n const mimeTypes: MimeTypes = {\n '.html': 'text/html',\n '.css': 'text/css',\n '.js': 'application/javascript',\n '.json': 'application/json',\n '.png': 'image/png',\n '.jpg': 'image/jpeg',\n '.jpeg': 'image/jpeg',\n '.gif': 'image/gif',\n '.svg': 'image/svg+xml',\n '.ico': 'image/x-icon',\n }\n\n const contentType = mimeTypes[ext] || 'application/octet-stream'\n res.setHeader('Content-Type', contentType)\n\n // Read and serve the file\n const fileStream = fs.createReadStream(filePath)\n fileStream.pipe(res)\n return\n }\n\n // If not handled, pass to next middleware\n next()\n })\n },\n }\n}\n"],"mappings":";;;;;AAMA,MAAM,YAAY,KAAK,QAAQ,cAAc,OAAO,KAAK,IAAI,CAAC;;;;AAiB9D,SAAwB,KAAK,UAA6B,EAAE,EAAU;CACpE,MAAM,EAAE,YAAY,YAAY;CAGhC,MAAM,aAAa,KAAK,KAAK,WAAW,MAAM,SAAS;CACvD,MAAM,UAAU,QAAQ,KAAK;AAE7B,QAAO;EACL,MAAM;EAEN,OAAO,QAAgC;GAErC,MAAM,SAAS,KAAK,QAAQ,SAAS,cAAc;GACnD,MAAM,SAAS,KAAK,QAAQ,SAAS,cAAc;GAEnD,IAAI,oBAAmC;AACvC,OAAI,GAAG,WAAW,OAAO,CACvB,qBAAoB;YACX,GAAG,WAAW,OAAO,CAC9B,qBAAoB;AAGtB,OAAI,CAAC,kBACH,QA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AI,KAAK,WAAW,OAAO,EAAE;KACtC,MAAM,kBAAkB,IAAI,IAAI,MAAM,IAAI,CAAC;AAC3C,gBAAW,KAAK,KACd,YACA,MACA,gBAAiB,QAAQ,QAAQ,GAAG,CACrC;eACQ,IAAI,KAAK,WAAW,QAAQ,EAAE;KACvC,MAAM,kBAAkB,IAAI,IAAI,MAAM,IAAI,CAAC;AAC3C,gBAAW,KAAK,KACd,YACA,OACA,gBAAiB,QAAQ,SAAS,GAAG,CACtC;eACQ,IAAI,KAAK,WAAW,WAAW,EAAE;KAC1C,MAAM,kBAAkB,IAAI,IAAI,MAAM,IAAI,CAAC;AAC3C,gBAAW,KAAK,KACd,YACA,UACA,gBAAiB,QAAQ,YAAY,GAAG,CACzC;eAED,IAAI,QAAQ,OACZ,IAAI,KAAK,WAAW,KAAK,IACzB,IAAI,QAAQ,iBACZ,IAAI,KAAK,WAAW,eAAe,CAEnC,YAAW,KAAK,KAAK,YAAY,aAAa;AAIhD,QAAI,YAAY,GAAG,WAAW,SAAS,EAAE;KAEvC,MAAM,MAAM,KAAK,QAAQ,SAAS,CAAC,aAAa;KAchD,MAAM,cAbuB;MAC3B,SAAS;MACT,QAAQ;MACR,OAAO;MACP,SAAS;MACT,QAAQ;MACR,QAAQ;MACR,SAAS;MACT,QAAQ;MACR,QAAQ;MACR,QAAQ;MACT,CAE6B,QAAQ;AACtC,SAAI,UAAU,gBAAgB,YAAY;AAGvB,QAAG,iBAAiB,SAAS,CACrC,KAAK,IAAI;AACpB;;AAIF,UAAM;KACN;;EAEL"}
package/package.json CHANGED
@@ -1,37 +1,35 @@
1
1
  {
2
2
  "name": "tona-vite",
3
- "type": "module",
4
- "version": "1.0.21",
3
+ "version": "1.0.22",
5
4
  "description": "Vite plugin for Tona themes - combines dynamic script extension and shared assets serving",
5
+ "keywords": [
6
+ "dynamic-script",
7
+ "plugin",
8
+ "shared-assets",
9
+ "vite",
10
+ "博客园"
11
+ ],
12
+ "homepage": "https://github.com/guangzan/tona/tree/main/packages/tona-vite#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/guangzan/tona/issues"
15
+ },
16
+ "license": "MIT",
6
17
  "author": {
7
18
  "name": "guangzan",
8
- "url": "https://www.cnblogs.com/guangzan",
9
- "email": "guangzan1999@outlook.com"
19
+ "email": "guangzan1999@outlook.com",
20
+ "url": "https://www.cnblogs.com/guangzan"
10
21
  },
11
- "license": "MIT",
12
- "homepage": "https://github.com/guangzan/tona/tree/main/packages/tona-vite#readme",
13
22
  "repository": {
14
23
  "type": "git",
15
24
  "url": "git+https://github.com/guangzan/tona.git",
16
25
  "directory": "packages/tona-vite"
17
26
  },
18
- "bugs": {
19
- "url": "https://github.com/guangzan/tona/issues"
20
- },
21
- "keywords": [
22
- "vite",
23
- "plugin",
24
- "dynamic-script",
25
- "shared-assets",
26
- "博客园"
27
+ "files": [
28
+ "dist",
29
+ "public"
27
30
  ],
31
+ "type": "module",
28
32
  "sideEffects": false,
29
- "exports": {
30
- ".": {
31
- "types": "./dist/index.d.mts",
32
- "import": "./dist/index.mjs"
33
- }
34
- },
35
33
  "main": "./dist/index.mjs",
36
34
  "module": "./dist/index.mjs",
37
35
  "types": "./dist/index.d.mts",
@@ -43,21 +41,23 @@
43
41
  ]
44
42
  }
45
43
  },
46
- "files": [
47
- "dist",
48
- "public"
49
- ],
50
- "peerDependencies": {
51
- "vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
44
+ "exports": {
45
+ ".": {
46
+ "types": "./dist/index.d.mts",
47
+ "import": "./dist/index.mjs"
48
+ }
52
49
  },
53
50
  "devDependencies": {
54
- "@types/node": "^25.0.3",
55
- "tsdown": "latest",
56
- "vite": "^7.3.1",
57
- "vitest": "^4.0.16"
51
+ "@types/node": "^25.5.0",
52
+ "vite": "npm:@voidzero-dev/vite-plus-core@latest",
53
+ "vite-plus": "latest",
54
+ "vitest": "npm:@voidzero-dev/vite-plus-test@latest"
55
+ },
56
+ "peerDependencies": {
57
+ "vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
58
58
  },
59
59
  "scripts": {
60
- "dev": "tsdown --watch",
61
- "build": "tsdown"
60
+ "dev": "vp pack --watch",
61
+ "build": "vp pack"
62
62
  }
63
63
  }