Skip to content

Commit e5af651

Browse files
committed
2.0.0 - Runs on build
1 parent 6f0a10b commit e5af651

8 files changed

Lines changed: 27 additions & 34 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vite-plugin-icons-spritesheet",
3-
"version": "1.3.0",
3+
"version": "2.0.0",
44
"description": "Vite plugin that generates a spritesheet out of your icons.",
55
"main": "./dist/index.js",
66
"module": "./dist/index.mjs",

src/index.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*eslint-disable no-console */
2-
import { promises as fs } from "fs";
3-
import path from "path";
2+
import { promises as fs } from "node:fs";
3+
import path from "node:path";
44
import { glob } from "glob";
55
import { parse } from "node-html-parser";
66
import chalk from "chalk";
77
import type { Plugin } from "vite";
88
import { normalizePath } from "vite";
9-
import { mkdir } from "fs/promises";
9+
import { mkdir } from "node:fs/promises";
1010

1111
interface PluginProps {
1212
withTypes?: boolean;
@@ -125,13 +125,13 @@ async function generateTypes({ names, outputPath }: { names: string[]; outputPat
125125
const output = [
126126
"// This file is generated by icon spritesheet generator",
127127
"",
128-
"export type IconName =",
129-
...names.map((name) => ` | "${name}"`),
130-
"",
128+
131129
"export const iconNames = [",
132130
...names.map((name) => ` "${name}",`),
133131
"] as const",
134132
"",
133+
"export type IconName = typeof iconNames[number]",
134+
"",
135135
].join("\n");
136136

137137
const file = await writeIfChanged(
@@ -160,6 +160,7 @@ async function writeIfChanged(filepath: string, newContent: string, message: str
160160
}
161161
}
162162

163+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
163164
export const iconsSpritesheet: (args: PluginProps) => any = ({
164165
withTypes,
165166
inputDir,
@@ -180,10 +181,7 @@ export const iconsSpritesheet: (args: PluginProps) => any = ({
180181
});
181182
return {
182183
name: "icon-spritesheet-generator",
183-
apply(config) {
184-
return config.mode === "development";
185-
},
186-
async configResolved() {
184+
async buildStart() {
187185
await iconGenerator();
188186
},
189187
async watchChange(file, type) {
@@ -198,5 +196,6 @@ export const iconsSpritesheet: (args: PluginProps) => any = ({
198196
await iconGenerator();
199197
}
200198
},
199+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
201200
} satisfies Plugin<any>;
202201
};
File renamed without changes.
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
// This file is generated by icon spritesheet generator
22

3-
export type IconName =
4-
| "Test"
5-
| "De"
6-
| "C"
7-
| "B"
8-
| "A"
9-
103
export const iconNames = [
114
"Test",
125
"De",
136
"C",
147
"B",
158
"A",
169
] as const
10+
11+
export type IconName = typeof iconNames[number]

test-apps/remix-vite/app/root.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import {
2-
Links,
3-
Meta,
4-
Outlet,
5-
Scripts,
6-
ScrollRestoration,
7-
} from "@remix-run/react";
1+
import { Links, Meta, Outlet, Scripts, ScrollRestoration } from "@remix-run/react";
82

93
export function Layout({ children }: { children: React.ReactNode }) {
104
return (

test-apps/remix-vite/app/routes/_index.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1+
import type { LinksFunction } from "@remix-run/node";
12
import type { MetaFunction } from "@remix-run/node";
23
// Import and test your package
4+
import sprite from "../icons/sprite.svg";
35

46
export const meta: MetaFunction = () => {
5-
return [{ title: "New Remix App" }, { name: "description", content: "Welcome to Remix!" }];
7+
return [{ title: "New Remix App" }, { name: "description", content: "Welcome to Remix!" }, {}];
68
};
79

10+
export const links: LinksFunction = () => [
11+
{
12+
href: sprite,
13+
rel: "icon",
14+
},
15+
];
16+
817
export default function Index() {
918
return (
1019
<div style={{ fontFamily: "system-ui, sans-serif", lineHeight: "1.8" }}>

test-apps/remix-vite/public/sprite.svg

Lines changed: 0 additions & 7 deletions
This file was deleted.

test-apps/remix-vite/vite.config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ export default defineConfig({
1212
iconsSpritesheet({
1313
withTypes: true,
1414
inputDir: "icons",
15-
outputDir: "public/icons",
15+
outputDir: "./app/icons",
1616
}),
1717
],
18+
build: {
19+
assetsInlineLimit: 0,
20+
},
1821
});

0 commit comments

Comments
 (0)