Browse Source

pref: split vendor chunks (#843)

* pref: split vendor chunks

Signed-off-by: ryjiang <jiangruiyi@gmail.com>

* fix: no git binary

Signed-off-by: ryjiang <jiangruiyi@gmail.com>

* fix: no git binary (#844)

* fix: no git binary

Signed-off-by: ryjiang <jiangruiyi@gmail.com>

* fix build

Signed-off-by: ryjiang <jiangruiyi@gmail.com>

---------

Signed-off-by: ryjiang <jiangruiyi@gmail.com>

* update

Signed-off-by: ryjiang <jiangruiyi@gmail.com>

---------

Signed-off-by: ryjiang <jiangruiyi@gmail.com>
ryjiang 2 weeks ago
parent
commit
6728037aad
2 changed files with 30 additions and 0 deletions
  1. 4 0
      Dockerfile
  2. 26 0
      client/vite.config.mts

+ 4 - 0
Dockerfile

@@ -35,6 +35,10 @@ RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
 
 # => Reinstall production dependencies and clean cache
 RUN yarn install --production && yarn cache clean
+
+# Remove git
+RUN apt-get remove -y git && rm -rf /var/lib/apt/lists/*
+
 # Make our shell script executable
 RUN chmod +x /app/build/env.sh
 

+ 26 - 0
client/vite.config.mts

@@ -10,6 +10,32 @@ export default defineConfig({
   // comment this out if that isn't relevant for your project
   build: {
     outDir: 'build',
+    rollupOptions: { // Add rollupOptions here
+      output: {
+        manualChunks(id) {
+          // Split vendor code into a separate chunk
+          if (id.includes('node_modules')) {
+            // Example: Split MUI into its own chunk
+            // if (id.includes('@mui')) {
+            //   return 'vendor-mui';
+            // }
+            // Example: Split react related libs into its own chunk
+            if (id.includes('react') || id.includes('react-dom')) {
+              return 'vendor-react';
+            }
+            // Example: Split codemirror related libs into its own chunk
+            if (id.includes('codemirror') || id.includes('@codemirror') || id.includes('@lezer')) {
+              return 'vendor-codemirror';
+            }
+            // Example: Split d3 into its own chunk
+            if (id.includes('d3')) {
+              return 'vendor-d3';
+            }
+            return 'vendor'; // All other node_modules go here
+          }
+        },
+      },
+    },
   },
   server: {
     port: 3001,