Fix: fix javascript heap out of memory error from vite

This commit is contained in:
Daniel D Orlando 2023-04-07 07:27:05 -07:00
parent 34c3663308
commit 6e42d4fa3d
2 changed files with 37 additions and 3 deletions

View file

@ -8,7 +8,7 @@
"ESNext"
],
"allowJs": true,
"skipLibCheck": true,
"skipLibCheck": false,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,

View file

@ -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: "" },
};
}
},
};
}