vite-plugin-for-svelte-svg 0.9.0 → 0.9.2

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
@@ -30,7 +30,7 @@ export default defineConfig({
30
30
  plugins: [
31
31
  svelteSvg({
32
32
  dir: 'src/svg',
33
- typesOutput: 'src/type/svg.d.ts'
33
+ output: 'src/svg/index.ts'
34
34
  }),
35
35
  svelte()
36
36
  ]
@@ -41,7 +41,7 @@ export default defineConfig({
41
41
 
42
42
  ```svelte
43
43
  <script lang="ts">
44
- import { Svg } from '@/type/svg' // Auto-generated with typed name prop
44
+ import { Svg } from './svg' // Auto-generated with typed name prop
45
45
  </script>
46
46
 
47
47
  <!-- Basic usage -->
@@ -72,7 +72,7 @@ export default defineConfig({
72
72
  | Option | Type | Default | Description |
73
73
  |--------|------|---------|-------------|
74
74
  | `dir` | `string` | `'src/svg'` | SVG files directory |
75
- | `typesOutput` | `string` | `'src/type/svg.d.ts'` | TypeScript types output path |
75
+ | `output` | `string` | `'src/svg/index.ts'` | Generated module output path |
76
76
  | `generateTypes` | `boolean` | `true` | Whether to generate types |
77
77
 
78
78
  ### Svg Component Props
@@ -87,7 +87,7 @@ export default defineConfig({
87
87
 
88
88
  ### Generated File
89
89
 
90
- The plugin generates a single `svg.ts` file containing:
90
+ The plugin generates a single `index.ts` file containing:
91
91
 
92
92
  ```ts
93
93
  export type SvgName = 'icon1' | 'icon2' | ... // Union of all SVG names
@@ -97,7 +97,7 @@ export const Svg: Component<SvgProps> // Typed Svg component
97
97
 
98
98
  ## How It Works
99
99
 
100
- 1. **Build/Dev start**: Plugin scans SVG directory and generates `svg.ts` with typed `Svg` component
100
+ 1. **Build/Dev start**: Plugin scans SVG directory and generates `index.ts` with typed `Svg` component
101
101
  2. **Dev time**: Watches for SVG file changes and regenerates with HMR
102
102
  3. **Runtime**: SVGs are loaded as base64 data URLs via `import.meta.glob`, then parsed and modified in the browser
103
103
 
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Plugin } from 'vite';
2
- import { P as PluginOptions } from './types-Bh508a5v.js';
3
- export { N as NumberWithUnit, b as SvgBase64, a as SvgColor, S as SvgProps } from './types-Bh508a5v.js';
2
+ import { P as PluginOptions } from './types-Bc9GjRbg.js';
3
+ export { N as NumberWithUnit, b as SvgBase64, a as SvgColor, c as SvgGlobResult, S as SvgProps } from './types-Bc9GjRbg.js';
4
4
  import 'svelte/elements';
5
5
 
6
6
  declare function svelteSvgPlugin(options?: PluginOptions): Plugin;
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { writeFileSync, existsSync, mkdirSync } from "fs";
3
3
  import { resolve, dirname } from "path";
4
4
  import { glob } from "glob";
5
- function generateSvgTypes(svgDir, outputPath, root) {
5
+ function generateSvgModule(svgDir, outputPath, root) {
6
6
  const fullSvgDir = resolve(root, svgDir);
7
7
  const fullOutputPath = resolve(root, outputPath);
8
8
  const svgFiles = glob.sync(`${fullSvgDir}/**/*.svg`);
@@ -14,7 +14,6 @@ function generateSvgTypes(svgDir, outputPath, root) {
14
14
  const svgNameType = svgNames.length > 0 ? svgNames.map((name) => `'${name}'`).join(" | ") : "string";
15
15
  const outputDir = dirname(fullOutputPath);
16
16
  const relativeSvgDir = resolve(root, svgDir).replace(/\\/g, "/");
17
- const relativeOutputDir = outputDir.replace(/\\/g, "/");
18
17
  let importPath = relativeSvgDir.replace(root.replace(/\\/g, "/"), "");
19
18
  if (!importPath.startsWith("/")) importPath = "/" + importPath;
20
19
  const moduleContent = `// Auto-generated by vite-plugin-for-svelte-svg
@@ -40,14 +39,13 @@ export const Svg = BaseSvg as Component<SvgProps>
40
39
  if (!existsSync(outputDir)) {
41
40
  mkdirSync(outputDir, { recursive: true });
42
41
  }
43
- const tsOutputPath = fullOutputPath.replace(".d.ts", ".ts");
44
- writeFileSync(tsOutputPath, moduleContent);
45
- console.log(`[vite-plugin-for-svelte-svg] Generated: ${outputPath.replace(".d.ts", ".ts")}`);
42
+ writeFileSync(fullOutputPath, moduleContent);
43
+ console.log(`[vite-plugin-for-svelte-svg] Generated: ${outputPath}`);
46
44
  }
47
45
  function svelteSvgPlugin(options = {}) {
48
46
  const {
49
47
  dir = "src/svg",
50
- typesOutput = "src/types/svg.d.ts",
48
+ output = "src/svg/index.ts",
51
49
  generateTypes = true
52
50
  } = options;
53
51
  let root = process.cwd();
@@ -58,7 +56,7 @@ function svelteSvgPlugin(options = {}) {
58
56
  },
59
57
  buildStart() {
60
58
  if (generateTypes) {
61
- generateSvgTypes(dir, typesOutput, root);
59
+ generateSvgModule(dir, output, root);
62
60
  }
63
61
  },
64
62
  configureServer(server) {
@@ -66,7 +64,7 @@ function svelteSvgPlugin(options = {}) {
66
64
  const fullSvgDir = resolve(root, dir);
67
65
  server.watcher.add(fullSvgDir);
68
66
  const handleChange = () => {
69
- generateSvgTypes(dir, typesOutput, root);
67
+ generateSvgModule(dir, output, root);
70
68
  server.ws.send({ type: "full-reload" });
71
69
  };
72
70
  server.watcher.on("add", (path) => {
@@ -1,6 +1,6 @@
1
1
  export { default as Svg } from './Svg.svelte';
2
- import { c as SvgModule, d as SvgRegistry } from '../types-Bh508a5v.js';
3
- export { N as NumberWithUnit, b as SvgBase64, a as SvgColor, S as SvgProps } from '../types-Bh508a5v.js';
2
+ import { c as SvgGlobResult, d as SvgRegistry } from '../types-Bc9GjRbg.js';
3
+ export { N as NumberWithUnit, b as SvgBase64, a as SvgColor, e as SvgModule, S as SvgProps } from '../types-Bc9GjRbg.js';
4
4
  import 'svelte/elements';
5
5
 
6
6
  /**
@@ -9,6 +9,6 @@ import 'svelte/elements';
9
9
  * import { initSvg } from 'vite-plugin-for-svelte-svg/runtime'
10
10
  * initSvg(import.meta.glob('./your-svg-dir/*.svg'))
11
11
  */
12
- declare function initSvg(globResult: Record<string, SvgModule>): SvgRegistry;
12
+ declare function initSvg(globResult: SvgGlobResult): SvgRegistry;
13
13
 
14
- export { SvgModule, SvgRegistry, initSvg };
14
+ export { SvgRegistry, initSvg };
@@ -7,10 +7,10 @@ interface PluginOptions {
7
7
  */
8
8
  dir?: string;
9
9
  /**
10
- * Output path for generated TypeScript types
11
- * @default 'src/types/svg.d.ts'
10
+ * Output path for generated TypeScript module
11
+ * @default 'src/svg/index.ts'
12
12
  */
13
- typesOutput?: string;
13
+ output?: string;
14
14
  /**
15
15
  * Whether to generate types on startup
16
16
  * @default true
@@ -28,6 +28,7 @@ interface SvgProps extends Omit<HTMLAttributes<HTMLElement>, 'color'> {
28
28
  type SvgModule = () => Promise<{
29
29
  default: string;
30
30
  }>;
31
+ type SvgGlobResult = Record<string, () => Promise<any>>;
31
32
  type SvgRegistry = Record<string, SvgModule>;
32
33
 
33
- export type { NumberWithUnit as N, PluginOptions as P, SvgProps as S, SvgColor as a, SvgBase64 as b, SvgModule as c, SvgRegistry as d };
34
+ export type { NumberWithUnit as N, PluginOptions as P, SvgProps as S, SvgColor as a, SvgBase64 as b, SvgGlobResult as c, SvgRegistry as d, SvgModule as e };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-for-svelte-svg",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "Vite plugin for SVG handling in Svelte projects with dynamic color and size support",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",