From 04339451497758aec9945d68e1b7ceac24f66f2b Mon Sep 17 00:00:00 2001 From: ryoppippi <1560508+ryoppippi@users.noreply.github.com> Date: Sat, 13 Jul 2024 23:02:02 +0100 Subject: [PATCH 1/2] refactor(package.json): add optional svelte support This commit adds optional support for Svelte in the unplugin-typia package. This allows the package to be used in projects that are based on Svelte, expanding its usability. --- packages/unplugin-typia/package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/unplugin-typia/package.json b/packages/unplugin-typia/package.json index 5a8e78ed..9e545287 100644 --- a/packages/unplugin-typia/package.json +++ b/packages/unplugin-typia/package.json @@ -77,6 +77,9 @@ "rollup": { "optional": true }, + "svelte": { + "optional": true + }, "vite": { "optional": true }, From 51fef1c28bc989ebef408936696d12f30dd723ba Mon Sep 17 00:00:00 2001 From: ryoppippi <1560508+ryoppippi@users.noreply.github.com> Date: Sat, 13 Jul 2024 23:02:55 +0100 Subject: [PATCH 2/2] refactor(svelte): dynamically import sveltePreprocess This commit changes the import of `sveltePreprocess` from a static import to a dynamic one. This is done in the `preprocess` function in `svelte.ts`. The change could potentially improve the load time and overall performance of the application. --- packages/unplugin-typia/src/core/languages/svelte.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/unplugin-typia/src/core/languages/svelte.ts b/packages/unplugin-typia/src/core/languages/svelte.ts index 34bf95a1..204d392e 100644 --- a/packages/unplugin-typia/src/core/languages/svelte.ts +++ b/packages/unplugin-typia/src/core/languages/svelte.ts @@ -1,4 +1,3 @@ -import { preprocess as sveltePreprocess } from 'svelte/compiler'; import type { Data, ID, Source } from '../types.js'; import { wrap } from '../types.js'; @@ -24,6 +23,7 @@ export async function preprocess( { source, id, transform }: { source: Source; id: ID; transform: TransformFunction }, ): Promise<{ code: Data }> { + const { preprocess: sveltePreprocess } = await import('svelte/compiler'); const { code } = await sveltePreprocess(source, { script: async ({ content, filename, attributes }) => { if (filename == null) {