@onedarnleyroad/vite-plugin-svg-sprite 2.0.0-beta.0 → 2.0.0-beta.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/README.md CHANGED
@@ -82,28 +82,28 @@ Each SVG becomes a `<symbol>` with `id="svg-{filename}"`. For example, `arrow.sv
82
82
 
83
83
  ### With Vite manifest (recommended)
84
84
 
85
- With `build.manifest: true` enabled, each sprite is registered in `manifest.json` keyed by its logical name:
85
+ With `build.manifest: true` enabled, each sprite is registered in `manifest.json` keyed by its `inputDir`-relative path:
86
86
 
87
87
  ```json
88
88
  {
89
- "sprite.svg": { "file": "assets/sprite-DAskUDYW.svg", "src": "sprite.svg", "isEntry": false },
90
- "sprite-light.svg": { "file": "assets/sprite-light-xV7q1sYy.svg", "src": "sprite-light.svg", "isEntry": false }
89
+ "src/icons/sprite.svg": { "file": "assets/sprite-DAskUDYW.svg", "src": "src/icons/sprite.svg", "isEntry": false },
90
+ "src/icons/sprite-light.svg": { "file": "assets/sprite-light-xV7q1sYy.svg", "src": "src/icons/sprite-light.svg", "isEntry": false }
91
91
  }
92
92
  ```
93
93
 
94
- With Craft CMS + [nystudio107/craft-vite](https://nystudio107.com/docs/vite/):
94
+ With Craft CMS + [nystudio107/craft-vite](https://nystudio107.com/docs/vite/), use `craft.vite.asset()` — **not `entry()`**. The `asset()` helper is dev-server-aware; `entry()` always reads the manifest, so in dev it would serve stale built files:
95
95
 
96
96
  ```twig
97
97
  <svg aria-hidden="true">
98
- <use href="{{ craft.vite.entry('sprite.svg') }}#svg-arrow"></use>
98
+ <use href="{{ craft.vite.asset('src/icons/sprite.svg') }}#svg-arrow"></use>
99
99
  </svg>
100
100
 
101
101
  <svg aria-hidden="true">
102
- <use href="{{ craft.vite.entry('sprite-light.svg') }}#svg-sun"></use>
102
+ <use href="{{ craft.vite.asset('src/icons/sprite-light.svg') }}#svg-sun"></use>
103
103
  </svg>
104
104
  ```
105
105
 
106
- In dev mode, `craft.vite.entry('sprite.svg')` returns the raw path (`/sprite.svg`), which the plugin's dev middleware serves. In production it returns the hashed path from the manifest.
106
+ In dev, `asset()` returns the Vite dev-server URL (e.g. `https://…:3000/src/icons/sprite.svg`), which the plugin's in-memory middleware serves. In production it returns the hashed URL from the manifest.
107
107
 
108
108
  ### Without manifest
109
109
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onedarnleyroad/vite-plugin-svg-sprite",
3
- "version": "2.0.0-beta.0",
3
+ "version": "2.0.0-beta.1",
4
4
  "description": "Vite plugin that builds an SVG sprite sheet from a directory of SVG files",
5
5
  "type": "module",
6
6
  "exports": {
package/src/index.js CHANGED
@@ -98,8 +98,9 @@ export default function svgSpritePlugin(options = {}) {
98
98
  const source = buildSpriteSvg(group.dir, group.files)
99
99
  const base = group.logicalName.replace(/\.svg$/, '')
100
100
  const hashedFileName = join(outputDir, `${base}-${hashContent(source)}.svg`)
101
+ const key = join(inputDir, group.logicalName)
101
102
  this.emitFile({ type: 'asset', fileName: hashedFileName, source })
102
- emitted.push({ logicalName: group.logicalName, fileName: hashedFileName })
103
+ emitted.push({ key, fileName: hashedFileName })
103
104
  }
104
105
  },
105
106
 
@@ -114,10 +115,10 @@ export default function svgSpritePlugin(options = {}) {
114
115
 
115
116
  const manifest = JSON.parse(readFileSync(manifestPath, 'utf-8'))
116
117
 
117
- for (const { logicalName, fileName } of emitted) {
118
- manifest[logicalName] = {
118
+ for (const { key, fileName } of emitted) {
119
+ manifest[key] = {
119
120
  file: fileName,
120
- src: logicalName,
121
+ src: key,
121
122
  isEntry: false,
122
123
  }
123
124
  }
@@ -131,7 +132,8 @@ export default function svgSpritePlugin(options = {}) {
131
132
  const rebuild = () => {
132
133
  sprites.clear()
133
134
  for (const group of collectSpriteGroups(inputDir, prefix)) {
134
- sprites.set(group.logicalName, buildSpriteSvg(group.dir, group.files))
135
+ const key = join(inputDir, group.logicalName)
136
+ sprites.set(key, buildSpriteSvg(group.dir, group.files))
135
137
  }
136
138
  }
137
139
  rebuild()