From 6e42d4fa3da81ab5f0c3da1a219ba9e50de95ff9 Mon Sep 17 00:00:00 2001 From: Daniel D Orlando Date: Fri, 7 Apr 2023 07:27:05 -0700 Subject: [PATCH] Fix: fix javascript heap out of memory error from vite --- client/tsconfig.json | 2 +- client/vite.config.ts | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/client/tsconfig.json b/client/tsconfig.json index c9ae48d29..fd38a638a 100644 --- a/client/tsconfig.json +++ b/client/tsconfig.json @@ -8,7 +8,7 @@ "ESNext" ], "allowJs": true, - "skipLibCheck": true, + "skipLibCheck": false, "esModuleInterop": true, "allowSyntheticDefaultImports": true, "strict": true, diff --git a/client/vite.config.ts b/client/vite.config.ts index 73edb63a9..b9e3da31c 100644 --- a/client/vite.config.ts +++ b/client/vite.config.ts @@ -1,6 +1,7 @@ import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; import path from 'path'; +import type { Plugin } from "vite"; // https://vitejs.dev/config/ export default defineConfig({ @@ -19,11 +20,25 @@ export default defineConfig({ } } }, - plugins: [react()], + plugins: [react(), sourcemapExclude({ excludeNodeModules: true }),], publicDir: './public', build: { sourcemap: true, - outDir: './dist' + outDir: './dist', + rollupOptions: { + output: { + manualChunks: (id) => { + if (id.includes("node_modules")) { + return "vendor"; + } + }, + sourcemapIgnoreList: (relativeSourcePath) => { + const normalizedPath = path.normalize(relativeSourcePath); + return normalizedPath.includes("node_modules"); + }, + }, + cache: false, + }, }, resolve: { alias: { @@ -31,3 +46,22 @@ export default defineConfig({ } } }); + +interface SourcemapExclude { + excludeNodeModules?: boolean; +} +export function sourcemapExclude(opts?: SourcemapExclude): Plugin { + return { + name: "sourcemap-exclude", + transform(code: string, id: string) { + if (opts?.excludeNodeModules && id.includes("node_modules")) { + return { + code, + // https://github.com/rollup/rollup/blob/master/docs/plugin-development/index.md#source-code-transformations + map: { mappings: "" }, + }; + } + }, + }; +} +