@@ -7,6 +7,26 @@ import mdx from '@mdx-js/rollup'
77import remarkGfm from 'remark-gfm'
88import remarkFrontmatter from 'remark-frontmatter'
99import { nitroV2Plugin } from '@tanstack/nitro-v2-vite-plugin'
10+ import type { Plugin } from 'vite'
11+
12+ // Plugin to prevent duplicate CSS injection
13+ const preventDuplicateCSS = ( ) : Plugin => ( {
14+ name : 'prevent-duplicate-css' ,
15+ enforce : 'post' ,
16+ generateBundle ( _options , bundle ) {
17+ // Find all CSS assets
18+ const cssAssets = Object . entries ( bundle ) . filter (
19+ ( [ , asset ] ) => asset . type === 'asset' && asset . fileName . endsWith ( '.css' )
20+ )
21+
22+ // If there are multiple CSS files, keep only the last one (most recent)
23+ if ( cssAssets . length > 1 ) {
24+ cssAssets . slice ( 0 , - 1 ) . forEach ( ( [ name ] ) => {
25+ delete bundle [ name ]
26+ } )
27+ }
28+ } ,
29+ } )
1030
1131const config = defineConfig ( {
1232 plugins : [
@@ -26,15 +46,23 @@ const config = defineConfig({
2646 remarkPlugins : [ remarkGfm , remarkFrontmatter ] ,
2747 } ) ,
2848 viteReact ( ) ,
49+ preventDuplicateCSS ( ) ,
2950 ] ,
3051 ssr : {
3152 external : [ '@vercel/og' , 'satori' , 'yoga-wasm-web' ] ,
53+ noExternal : true ,
3254 } ,
3355 build : {
3456 cssCodeSplit : false ,
3557 rollupOptions : {
3658 output : {
3759 manualChunks : undefined ,
60+ assetFileNames : ( assetInfo ) => {
61+ if ( assetInfo . name === 'styles.css' ) {
62+ return 'assets/styles-[hash][extname]' ;
63+ }
64+ return 'assets/[name]-[hash][extname]' ;
65+ } ,
3866 } ,
3967 } ,
4068 } ,
0 commit comments