Skip to content

Commit

Permalink
feat: re-add virtual module (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcansh authored Apr 10, 2024
1 parent 6996772 commit 41f7c0c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/small-pianos-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@mcansh/vite-svg-sprite-plugin": patch
---

re-add virtual module support
2 changes: 2 additions & 0 deletions examples/remix/app/routes/_index/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import archiveBoxArrowDownIconHref from "~/assets/archive-box-arrow-down.svg";
import beakerIconHref from "heroicons/24/outline/beaker.svg";
import eyeIconHref from "lucide-static/icons/eye.svg";
import homeIconHref from "lucide-static/icons/home.svg";
import spriteUrl from "virtual:@mcansh/vite-svg-sprite-plugin";
import { Icon } from "./icon";

export const meta: MetaFunction = () => {
Expand All @@ -16,6 +17,7 @@ export default function Index() {
return (
<div style={{ fontFamily: "system-ui, sans-serif", lineHeight: "1.8" }}>
<h1>Welcome to Remix</h1>
<h2>{spriteUrl}</h2>

<Icon icon={archiveBoxArrowDownIconHref} width={100} height={100} />
<Icon icon={beakerIconHref} width={100} height={100} />
Expand Down
2 changes: 1 addition & 1 deletion examples/remix/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default defineConfig({
tsconfigPaths(),
createSvgSpritePlugin({
logging: true,
spriteOutputName: "some-file.svg",
spriteOutputName: "mysvgsprite.svg",
}),
],
});
4 changes: 2 additions & 2 deletions packages/vite-svg-sprite-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ export function createSvgSpritePlugin(configOptions?: Config): Array<Plugin> {

async load(id) {
if (id === resolvedVirtualModuleId) {
warn(`the virtual module has been temporarily disabled`);
return js`export default "";`;
let spriteUrl = `/${config.build.assetsDir}/${options.spriteOutputName}`;
return js`export default ${JSON.stringify(spriteUrl)}`;
}
},

Expand Down

0 comments on commit 41f7c0c

Please sign in to comment.