Skip to content

Commit 8e3bd1f

Browse files
committed
Add manual chunks with Rollup for prod
1 parent 919c37e commit 8e3bd1f

File tree

3 files changed

+229
-155
lines changed

3 files changed

+229
-155
lines changed

apps/typegpu-docs/astro.config.mjs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import wasm from 'vite-plugin-wasm';
1313
import basicSsl from '@vitejs/plugin-basic-ssl';
1414
import rehypeMathJax from 'rehype-mathjax';
1515
import remarkMath from 'remark-math';
16+
import { relative, resolve } from 'pathe';
1617

1718
/**
1819
* @template T
@@ -22,6 +23,7 @@ const stripFalsy = (items) =>
2223
items.filter(/** @return {item is Exclude<T, boolean>} */ (item) => !!item);
2324

2425
const DEV = import.meta.env.DEV;
26+
const EXAMPLES_DIR = resolve('./src/examples');
2527

2628
// https://astro.build/config
2729
export default defineConfig({
@@ -41,6 +43,24 @@ export default defineConfig({
4143
rehypePlugins: [rehypeMathJax],
4244
},
4345
vite: {
46+
build: {
47+
rollupOptions: {
48+
output: {
49+
manualChunks(id) {
50+
if (id.startsWith(EXAMPLES_DIR) && id.endsWith('.ts')) {
51+
const relativePath = relative(EXAMPLES_DIR, id);
52+
const [category, example] = relativePath.split('/');
53+
if (example === undefined) {
54+
return null;
55+
}
56+
57+
return `example-${category}--${example}`;
58+
}
59+
},
60+
onlyExplicitManualChunks: true,
61+
},
62+
},
63+
},
4464
define: {
4565
// Required for '@rolldown/browser' to work.
4666
'process.env.NODE_DEBUG_NATIVE': '""',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"sharp"
6565
],
6666
"overrides": {
67-
"rollup": "4.34.8",
67+
"rollup": "^4.55.1",
6868
"three": "catalog:example"
6969
}
7070
}

0 commit comments

Comments
 (0)