knip.ts
1 import sveltePreprocess from 'svelte-preprocess' 2 import { preprocess, compile } from 'svelte/compiler' 3 import type { KnipConfig } from 'knip' 4 5 const sveltePreprocessor = sveltePreprocess() 6 7 const config: KnipConfig = { 8 ignore: ['**/*.d.ts'], 9 paths: { 10 // This ain't pretty, but Svelte basically does the same 11 '$app/*': ['node_modules/@sveltejs/kit/src/runtime/app/*'], 12 '$env/*': ['.svelte-kit/ambient.d.ts'], 13 '$lib/*': ['src/lib/*'], 14 }, 15 compilers: { 16 svelte: async (text: string) => { 17 const processed = await preprocess(text, sveltePreprocessor, { filename: 'dummy.ts' }) 18 const compiled = compile(processed.code) 19 return compiled.js.code 20 }, 21 css: (text: string) => [...text.matchAll(/(?<=@)import[^;]+/g)].join('\n'), 22 }, 23 } 24 25 export default config