From 83041c3e525e8419b474f353ff70030baa2cd281 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Tue, 23 Apr 2024 13:00:34 +0200 Subject: [PATCH] Provide function for manualChunks Instead of hardcoding the manualChunks this allows us to reduce chunk size of index, and make it more flexible for new dependencies. --- vite.config.ts | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/vite.config.ts b/vite.config.ts index bfbe6ca2d..0d1746d0d 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -42,32 +42,16 @@ export default defineConfig({ outDir: "build", rollupOptions: { output: { - manualChunks: { - markdown: [ - "@radicle/gray-matter", - "dompurify", - "hast-util-to-dom", - "hast-util-to-html", - "katex", - "marked", - ], - syntax: ["@wooorm/starry-night"], - grammarsTsx: [ - "@wooorm/starry-night/source.ts", - "@wooorm/starry-night/source.tsx", - ], - grammars: [ - "@wooorm/starry-night/source.python", - "@wooorm/starry-night/source.js", - "@wooorm/starry-night/source.perl", - "@wooorm/starry-night/source.haskell", - "@wooorm/starry-night/source.ruby", - "@wooorm/starry-night/source.css", - "@wooorm/starry-night/source.solidity", - "@wooorm/starry-night/source.cs", - "@wooorm/starry-night/source.swift", - ], - dom: ["svelte", "twemoji"], + manualChunks: id => { + if (id.includes("lodash")) { + return "lodash"; + } else if (id.includes("katex")) { + return "katex"; + } else if (id.includes("node_modules")) { + return "vendor"; + } else if (id.includes("components")) { + return "components"; + } }, }, },