Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add runtime/sveltekit-support #48

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = defineConfig({
rules: {},
},
{
files: ["esbuild.ts", "index.ts", "rollup.ts", "rspack.ts", "vite.ts", "webpack.ts", "nuxt.ts"],
files: ["esbuild.ts", "index.ts", "rollup.ts", "rspack.ts", "vite.ts", "webpack.ts", "nuxt.ts", "runtime.ts"],
rules: {
"import/no-unused-modules": "off",
},
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ See [the Nuxt example](examples/nuxt) for a working example project.
<br></details>

<details>
<summary>SvelteKit (No Supported for now, see <a href="https://github.com/sveltejs/kit/issues/5346">Vite Plugin</a>)</summary><br>
<summary>SvelteKit

The `@anolilab/unplugin-favicons` plugin should be configured in the `vite.config.js` configuration file:

Expand All @@ -219,6 +219,20 @@ export default defineConfig({
});
```

Then add `src/hooks.server.ts` to rewrite the head tag with [`hooks`](https://kit.svelte.dev/docs/hooks):

```ts
import head from "@anolilab/unplugin-favicons/runtime"; // use default import
import type { Handle } from "@sveltejs/kit";

export const handle: Handle = async ({ event, resolve }) => {
const response = await resolve(event, {
transformPageChunk: ({ html }) => html.replace("</head>", `${head}</head>`),
});
return response;
};
```

Check instructions in the `Frameworks -> Svelte` section below if you faced module import errors.

See [the SvelteKit example](examples/sveltekit) for a working example project.
Expand Down
1 change: 1 addition & 0 deletions examples/sveltekit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@neoconfetti/svelte": "^2.2.1",
"@sveltejs/adapter-auto": "^3.2.2",
"@sveltejs/kit": "^2.5.18",
"@sveltejs/vite-plugin-svelte": "3.1.1",
"@types/cookie": "^0.6.0",
"svelte": "^4.2.18",
"svelte-check": "^3.8.4",
Expand Down
1 change: 0 additions & 1 deletion examples/sveltekit/src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width" />
%sveltekit.head%
</head>
Expand Down
9 changes: 9 additions & 0 deletions examples/sveltekit/src/hooks.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import head from "@anolilab/unplugin-favicons/runtime";
import type { Handle } from "@sveltejs/kit";

export const handle: Handle = async ({ event, resolve }) => {
const response = await resolve(event, {
transformPageChunk: ({ html }) => html.replace("</head>", `${head}</head>`),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

});
return response;
};
2 changes: 1 addition & 1 deletion examples/sveltekit/svelte.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import adapter from "@sveltejs/adapter-auto";
import { vitePreprocess } from "@sveltejs/kit/vite";
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


/** @type {import('@sveltejs/kit').Config} */
const config = {
Expand Down
7 changes: 6 additions & 1 deletion examples/sveltekit/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@ import { defineConfig } from "vite";
import faviconsPlugin from "@anolilab/unplugin-favicons/vite";

export default defineConfig({
plugins: [sveltekit(), faviconsPlugin()],
plugins: [
sveltekit(),
faviconsPlugin({
logo: "./static/favicon.png",
}),
],
});
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@
"types": "./dist/nuxt.d.mts",
"default": "./dist/nuxt.mjs"
},
"./runtime": {
"import": {
"types": "./dist/runtime.d.mts",
"default": "./dist/runtime.mjs"
}
},
"./package.json": "./package.json"
},
"module": "dist/index.mjs",
Expand Down Expand Up @@ -111,6 +117,9 @@
"consola": "3.2.3",
"fast-json-stable-stringify": "^2.1.0",
"find-cache-dir": "^5.0.0",
"knitwork": "1.1.0",
"magic-string": "0.30.10",
"mlly": "1.7.1",
"parse-author": "^2.0.0",
"parse5": "^7.1.2",
"read-pkg-up": "^10.1.0",
Expand Down
Loading
Loading