Skip to content

Commit

Permalink
Improvements with v1.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
AlemTuzlak committed May 16, 2024
1 parent b9752e8 commit 1bdd0f6
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vite-plugin-icons-spritesheet",
"version": "1.1.1",
"version": "1.1.2",
"description": "Vite plugin that generates a spritesheet out of your icons.",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
25 changes: 9 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ async function generateSvgSprite({
})
);
const output = [
'<?xml version="1.0" encoding="UTF-8"?>',
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="0" height="0">',
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"0\" height=\"0\">",
"<defs>", // for semantics: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/defs
...symbols.filter(Boolean),
"</defs>",
Expand Down Expand Up @@ -141,20 +141,13 @@ export const iconsSpritesheet: (args: PluginProps) => Plugin = ({ withTypes, inp
apply(config) {
return config.mode === "development";
},
async configResolved(config) {
const outputSvgPath = normalizePath(path.join(cwd ?? process.cwd(), outputDir, fileName ?? "sprite.svg"));
const outputSvgExists = await fs
.access(outputSvgPath, fs.constants.F_OK)
.then(() => true)
.catch(() => false);
if (!outputSvgExists) {
await generateIcons({
withTypes,
inputDir,
outputDir,
fileName,
});
}
async configResolved() {
await generateIcons({
withTypes,
inputDir,
outputDir,
fileName,
});
},
async watchChange(file, type) {
const inputPath = normalizePath(path.join(cwd ?? process.cwd(), inputDir));
Expand Down
1 change: 1 addition & 0 deletions test-apps/remix-vite/icons/bs.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion test-apps/remix-vite/icons/d.svg

This file was deleted.

2 changes: 1 addition & 1 deletion test-apps/remix-vite/icons/de.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion test-apps/remix-vite/public/icons/sprite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test-apps/remix-vite/public/icons/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
export type IconName =
| "Test"
| "De"
| "D"
| "C"
| "Bs"
| "B"
| "A"

export const iconNames = [
"Test",
"De",
"D",
"C",
"Bs",
"B",
"A",
] as const

0 comments on commit 1bdd0f6

Please sign in to comment.