@@ -13,6 +13,7 @@ import wasm from 'vite-plugin-wasm';
1313import basicSsl from '@vitejs/plugin-basic-ssl' ;
1414import rehypeMathJax from 'rehype-mathjax' ;
1515import 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
2425const DEV = import . meta. env . DEV ;
26+ const EXAMPLES_DIR = resolve ( './src/examples' ) ;
2527
2628// https://astro.build/config
2729export 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' : '""' ,
0 commit comments