File size: 1,575 Bytes
b2ecf7d
0f1eb94
 
b2ecf7d
0f1eb94
 
 
b2ecf7d
0f1eb94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7a5b4bb
 
 
 
0f1eb94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b2ecf7d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { sveltekit } from "@sveltejs/kit/vite";
import { svelte } from "@sveltejs/vite-plugin-svelte";
import sveltePreprocess from "svelte-preprocess";
import { defineConfig } from "vite";
import dts from "vite-plugin-dts";
import { dirname } from "node:path";
import { fileURLToPath } from "node:url";

const __dirname = dirname(fileURLToPath(import.meta.url));
const isSSR = process.argv.includes("--ssr");

export default defineConfig(({ mode }) => {
	if (mode === "lib") {
		return {
			plugins: [
				svelte({
					configFile: false,
					extensions: [".svelte"],

					// eslint-disable-next-line
					// @ts-ignore see https://github.com/sveltejs/svelte-preprocess/issues/591
					preprocess: sveltePreprocess({
						typescript: { tsconfigFile: `${__dirname}/tsconfig.json` },
					}),
					emitCss: false,
					compilerOptions: {
						hydratable: true,
						generate: isSSR ? "ssr" : "dom",
					},
				}),
				dts({
					entryRoot: "src/lib",
				}),
			],
			build: {
				manifest: true,
				outDir: `dist/${isSSR ? "server" : "client"}`,
				rollupOptions: {
					input: {
						index: "src/lib/index.ts",
					},
					preserveEntrySignatures: "strict",
					output: [
						{
							preserveModules: true,
							format: "cjs",
							entryFileNames: "[name].cjs",
						},
						{
							preserveModules: true,
							format: "es",
							entryFileNames: "[name].js",
						},
					],
					external: ["svelte", /svelte\/(.*)/, "@huggingface/tasks"],
				},
			},
		};
	}

	if (mode === "app") {
		return {
			plugins: [sveltekit()],
		};
	}

	return {};
});