tona-vite 0.0.4 → 0.0.8

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
@@ -23,8 +23,11 @@ export default defineConfig({
23
23
 
24
24
  ## Features
25
25
 
26
- - Automatically detects main.ts or main.js files and replaces script src in HTML
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
27
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
28
31
  - Works in both development and build modes
29
32
 
30
33
  ## Options
@@ -32,19 +35,29 @@ export default defineConfig({
32
35
  ```ts
33
36
  interface TonaPluginOptions {
34
37
  /**
35
- * Default script source path when neither main.ts nor main.js exists
36
- * @default '/src/main.js'
38
+ * Theme name for build output filename
39
+ * @default 'theme'
37
40
  */
38
- defaultScriptSrc?: string
39
- /**
40
- * Base directory to resolve main files from
41
- * @default process.cwd()
42
- */
43
- baseDir?: string
44
- /**
45
- * The path to the shared assets directory
46
- * @default path.join(__dirname, '..', 'public')
47
- */
48
- sharedAssetsPath?: string
41
+ themeName?: string
49
42
  }
50
43
  ```
44
+
45
+ ## Build Configuration
46
+
47
+ The plugin automatically configures Vite's build mode:
48
+
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)
53
+
54
+ ## Development Server
55
+
56
+ During development, the plugin serves static assets from the plugin's public directory:
57
+
58
+ - `/public/*` - General public assets
59
+ - `/templates/*` - HTML templates
60
+ - `/js/*` - JavaScript files
61
+ - `/css/*` - CSS files
62
+ - `/images/*` - Image files
63
+ - `/` or `/index.html` - Navigation index page
package/dist/index.cjs CHANGED
@@ -35,30 +35,38 @@ const __dirname$1 = node_path.default.dirname((0, node_url.fileURLToPath)(requir
35
35
  * Vite plugin for Tona themes - combines dynamic script extension and shared assets serving
36
36
  */
37
37
  function tona(options = {}) {
38
- const { defaultScriptSrc = "/src/main.js", baseDir = node_process.default.cwd(), sharedAssetsPath, themeName = "theme" } = options;
39
- const assetsPath = sharedAssetsPath || node_path.default.join(__dirname$1, "..", "public");
38
+ const { themeName = "theme" } = options;
39
+ const assetsPath = node_path.default.join(__dirname$1, "..", "public");
40
+ const baseDir = node_process.default.cwd();
40
41
  return {
41
42
  name: "vite-plugin-tona",
42
43
  config(config) {
43
- const entryPath = node_path.default.resolve(baseDir, "src/main.ts");
44
- if (!node_fs.default.existsSync(entryPath)) return config;
44
+ const tsPath = node_path.default.resolve(baseDir, "src/main.ts");
45
+ const jsPath = node_path.default.resolve(baseDir, "src/main.js");
46
+ let resolvedEntryPath = null;
47
+ if (node_fs.default.existsSync(tsPath)) resolvedEntryPath = tsPath;
48
+ else if (node_fs.default.existsSync(jsPath)) resolvedEntryPath = jsPath;
49
+ if (!resolvedEntryPath) return config;
45
50
  const existingLib = config.build?.lib;
46
51
  const libConfig = existingLib && typeof existingLib === "object" ? {
47
52
  ...existingLib,
48
53
  formats: existingLib.formats || ["iife"],
49
- entry: existingLib.entry || entryPath,
54
+ entry: existingLib.entry || resolvedEntryPath,
50
55
  name: existingLib.name || themeName,
51
- fileName: existingLib.fileName || (() => `${themeName}.min.js`)
56
+ fileName: existingLib.fileName || (() => `${themeName}.min.js`),
57
+ cssFileName: existingLib.cssFileName || `${themeName}.min.css`
52
58
  } : {
53
59
  formats: ["iife"],
54
- entry: entryPath,
60
+ entry: resolvedEntryPath,
55
61
  name: themeName,
56
- fileName: () => `${themeName}.min.js`
62
+ fileName: () => `${themeName}.min.js`,
63
+ cssFileName: `${themeName}.min.css`
57
64
  };
58
65
  return {
59
66
  ...config,
60
67
  build: {
61
68
  ...config.build,
69
+ cssCodeSplit: config.build?.cssCodeSplit ?? false,
62
70
  lib: libConfig
63
71
  }
64
72
  };
@@ -66,7 +74,7 @@ function tona(options = {}) {
66
74
  transformIndexHtml(html) {
67
75
  const jsPath = node_path.default.resolve(baseDir, "src/main.js");
68
76
  const tsPath = node_path.default.resolve(baseDir, "src/main.ts");
69
- let scriptSrc = defaultScriptSrc;
77
+ let scriptSrc = "/src/main.js";
70
78
  if (node_fs.default.existsSync(tsPath)) scriptSrc = "/src/main.ts";
71
79
  else if (node_fs.default.existsSync(jsPath)) scriptSrc = "/src/main.js";
72
80
  return html.replace(/<script type="module" src="[^"]*"><\/script>/, `<script type="module" src="${scriptSrc}"><\/script>`);
package/dist/index.d.cts CHANGED
@@ -2,21 +2,6 @@ import { Plugin } from "vite";
2
2
 
3
3
  //#region src/index.d.ts
4
4
  interface TonaPluginOptions {
5
- /**
6
- * Default script source path when neither main.ts nor main.js exists
7
- * @default '/src/main.js'
8
- */
9
- defaultScriptSrc?: string;
10
- /**
11
- * Base directory to resolve main files from
12
- * @default process.cwd()
13
- */
14
- baseDir?: string;
15
- /**
16
- * The path to the shared assets directory
17
- * @default path.join(__dirname, '..', 'public')
18
- */
19
- sharedAssetsPath?: string;
20
5
  /**
21
6
  * Theme name for build output filename
22
7
  * @default 'theme'
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;UAYiB,iBAAA;;AAAjB;AAqBC;;;;;;;;;;;;;;;;;;;;;;iBAKuB,IAAA,WAAc,oBAAyB"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;UAYiB,iBAAA;;AAAjB;AAMC;;;;;;;iBAKuB,IAAA,WAAc,oBAAyB"}
package/dist/index.d.mts CHANGED
@@ -2,21 +2,6 @@ import { Plugin } from "vite";
2
2
 
3
3
  //#region src/index.d.ts
4
4
  interface TonaPluginOptions {
5
- /**
6
- * Default script source path when neither main.ts nor main.js exists
7
- * @default '/src/main.js'
8
- */
9
- defaultScriptSrc?: string;
10
- /**
11
- * Base directory to resolve main files from
12
- * @default process.cwd()
13
- */
14
- baseDir?: string;
15
- /**
16
- * The path to the shared assets directory
17
- * @default path.join(__dirname, '..', 'public')
18
- */
19
- sharedAssetsPath?: string;
20
5
  /**
21
6
  * Theme name for build output filename
22
7
  * @default 'theme'
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;UAYiB,iBAAA;;AAAjB;AAqBC;;;;;;;;;;;;;;;;;;;;;;iBAKuB,IAAA,WAAc,oBAAyB"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;UAYiB,iBAAA;;AAAjB;AAMC;;;;;;;iBAKuB,IAAA,WAAc,oBAAyB"}
package/dist/index.mjs CHANGED
@@ -9,30 +9,38 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
9
9
  * Vite plugin for Tona themes - combines dynamic script extension and shared assets serving
10
10
  */
11
11
  function tona(options = {}) {
12
- const { defaultScriptSrc = "/src/main.js", baseDir = process.cwd(), sharedAssetsPath, themeName = "theme" } = options;
13
- const assetsPath = sharedAssetsPath || path.join(__dirname, "..", "public");
12
+ const { themeName = "theme" } = options;
13
+ const assetsPath = path.join(__dirname, "..", "public");
14
+ const baseDir = process.cwd();
14
15
  return {
15
16
  name: "vite-plugin-tona",
16
17
  config(config) {
17
- const entryPath = path.resolve(baseDir, "src/main.ts");
18
- if (!fs.existsSync(entryPath)) return config;
18
+ const tsPath = path.resolve(baseDir, "src/main.ts");
19
+ const jsPath = path.resolve(baseDir, "src/main.js");
20
+ let resolvedEntryPath = null;
21
+ if (fs.existsSync(tsPath)) resolvedEntryPath = tsPath;
22
+ else if (fs.existsSync(jsPath)) resolvedEntryPath = jsPath;
23
+ if (!resolvedEntryPath) return config;
19
24
  const existingLib = config.build?.lib;
20
25
  const libConfig = existingLib && typeof existingLib === "object" ? {
21
26
  ...existingLib,
22
27
  formats: existingLib.formats || ["iife"],
23
- entry: existingLib.entry || entryPath,
28
+ entry: existingLib.entry || resolvedEntryPath,
24
29
  name: existingLib.name || themeName,
25
- fileName: existingLib.fileName || (() => `${themeName}.min.js`)
30
+ fileName: existingLib.fileName || (() => `${themeName}.min.js`),
31
+ cssFileName: existingLib.cssFileName || `${themeName}.min.css`
26
32
  } : {
27
33
  formats: ["iife"],
28
- entry: entryPath,
34
+ entry: resolvedEntryPath,
29
35
  name: themeName,
30
- fileName: () => `${themeName}.min.js`
36
+ fileName: () => `${themeName}.min.js`,
37
+ cssFileName: `${themeName}.min.css`
31
38
  };
32
39
  return {
33
40
  ...config,
34
41
  build: {
35
42
  ...config.build,
43
+ cssCodeSplit: config.build?.cssCodeSplit ?? false,
36
44
  lib: libConfig
37
45
  }
38
46
  };
@@ -40,7 +48,7 @@ function tona(options = {}) {
40
48
  transformIndexHtml(html) {
41
49
  const jsPath = path.resolve(baseDir, "src/main.js");
42
50
  const tsPath = path.resolve(baseDir, "src/main.ts");
43
- let scriptSrc = defaultScriptSrc;
51
+ let scriptSrc = "/src/main.js";
44
52
  if (fs.existsSync(tsPath)) scriptSrc = "/src/main.ts";
45
53
  else if (fs.existsSync(jsPath)) scriptSrc = "/src/main.js";
46
54
  return html.replace(/<script type="module" src="[^"]*"><\/script>/, `<script type="module" src="${scriptSrc}"><\/script>`);
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["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 * Default script source path when neither main.ts nor main.js exists\n * @default '/src/main.js'\n */\n defaultScriptSrc?: string\n /**\n * Base directory to resolve main files from\n * @default process.cwd()\n */\n baseDir?: string\n /**\n * The path to the shared assets directory\n * @default path.join(__dirname, '..', 'public')\n */\n sharedAssetsPath?: string\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 {\n defaultScriptSrc = '/src/main.js',\n baseDir = process.cwd(),\n sharedAssetsPath,\n themeName = 'theme',\n } = options\n\n // Default path to shared assets\n const assetsPath = sharedAssetsPath || path.join(__dirname, '..', 'public')\n\n return {\n name: 'vite-plugin-tona',\n\n config(config: UserConfig): UserConfig {\n const entryPath = path.resolve(baseDir, 'src/main.ts')\n const entryExists = fs.existsSync(entryPath)\n\n if (!entryExists) {\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 || entryPath,\n name: existingLib.name || themeName,\n fileName: existingLib.fileName || (() => `${themeName}.min.js`),\n }\n : {\n formats: ['iife'] as LibraryFormats[],\n entry: entryPath,\n name: themeName,\n fileName: () => `${themeName}.min.js`,\n }\n\n return {\n ...config,\n build: {\n ...config.build,\n lib: libConfig,\n },\n }\n },\n\n transformIndexHtml(html) {\n // Dynamic script extension: 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 = defaultScriptSrc\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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7C,MAAM,kBAAkB,IAAI,IAAI,MAAM,IAAI,CAAC;AAC3C,gBAAW,KAAK,KACd,YACA,aACA,gBAAiB,QAAQ,eAAe,GAAG,CAC5C;eACQ,IAAI,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;AAI1C,KADmB,GAAG,iBAAiB,SAAS,CACrC,KAAK,IAAI;AACpB;;AAIF,UAAM;KACN;;EAEL"}
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`,\n }\n : {\n formats: ['iife'] as LibraryFormats[],\n entry: resolvedEntryPath,\n name: themeName,\n fileName: () => `${themeName}.min.js`,\n cssFileName: `${themeName}.min.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;IACA,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,GACC;IACA,SAAS,CAAC,OAAO;IACjB,OAAO;IACP,MAAM;IACN,gBAAgB,GAAG,UAAU;IAC7B,aAAa,GAAG,UAAU;IAC3B;AAEL,UAAO;IACL,GAAG;IACH,OAAO;KACL,GAAG,OAAO;KACV,cAAc,OAAO,OAAO,gBAAgB;KAC5C,KAAK;KACN;IACF;;EAGH,mBAAmB,MAAM;GAEvB,MAAM,SAAS,KAAK,QAAQ,SAAS,cAAc;GACnD,MAAM,SAAS,KAA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AM,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"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tona-vite",
3
3
  "type": "module",
4
- "version": "0.0.4",
4
+ "version": "0.0.8",
5
5
  "description": "Vite plugin for Tona themes - combines dynamic script extension and shared assets serving",
6
6
  "author": {
7
7
  "name": "guangzan",