diff --git a/src/node/build/build.ts b/src/node/build/build.ts index 1f193323..7f5d9b9f 100644 --- a/src/node/build/build.ts +++ b/src/node/build/build.ts @@ -45,7 +45,10 @@ export async function build( const appChunk = clientResult && (clientResult.output.find( - (chunk) => chunk.type === 'chunk' && chunk.isEntry + (chunk) => + chunk.type === 'chunk' && + chunk.isEntry && + chunk.facadeModuleId?.endsWith('.js') ) as OutputChunk) const cssChunk = ( diff --git a/src/node/build/bundle.ts b/src/node/build/bundle.ts index a3765d40..1ec51b37 100644 --- a/src/node/build/bundle.ts +++ b/src/node/build/bundle.ts @@ -38,70 +38,70 @@ export async function bundle( // resolve options to pass to vite const { rollupOptions } = options - const resolveViteConfig = async (ssr: boolean): Promise => { - // use different entry based on ssr or not - input['app'] = path.resolve(APP_PATH, ssr ? 'ssr.js' : 'index.js') - return { - root: config.srcDir, - base: config.site.base, - logLevel: 'warn', - plugins: await createVitePressPlugin( - config, - ssr, - pageToHashMap, - clientJSMap - ), - ssr: { - noExternal: ['vitepress', '@docsearch/css'] - }, - build: { - ...options, - emptyOutDir: true, - ssr, - outDir: ssr ? config.tempDir : config.outDir, - cssCodeSplit: false, - rollupOptions: { - ...rollupOptions, - input, - // important so that each page chunk and the index export things for each - // other - preserveEntrySignatures: 'allow-extension', - output: { - ...rollupOptions?.output, - ...(ssr - ? { - entryFileNames: `[name].js`, - chunkFileNames: `[name].[hash].js` - } - : { - chunkFileNames(chunk) { - // avoid ads chunk being intercepted by adblock - return /(?:Carbon|BuySell)Ads/.test(chunk.name) - ? `assets/chunks/ui-custom.[hash].js` - : `assets/chunks/[name].[hash].js` - }, - manualChunks(id, ctx) { - // move known framework code into a stable chunk so that - // custom theme changes do not invalidate hash for all pages - if (id.includes('plugin-vue:export-helper')) { - return 'framework' - } - if ( - isEagerChunk(id, ctx) && - (/@vue\/(runtime|shared|reactivity)/.test(id) || - /vitepress\/dist\/client/.test(id)) - ) { - return 'framework' - } - } - }) - } + const resolveViteConfig = async (ssr: boolean): Promise => ({ + root: config.srcDir, + base: config.site.base, + logLevel: 'warn', + plugins: await createVitePressPlugin( + config, + ssr, + pageToHashMap, + clientJSMap + ), + ssr: { + noExternal: ['vitepress', '@docsearch/css'] + }, + build: { + ...options, + emptyOutDir: true, + ssr, + outDir: ssr ? config.tempDir : config.outDir, + cssCodeSplit: false, + rollupOptions: { + ...rollupOptions, + input: { + ...input, + // use different entry based on ssr or not + app: path.resolve(APP_PATH, ssr ? 'ssr.js' : 'index.js') }, - // minify with esbuild in MPA mode (for CSS) - minify: ssr ? (config.mpa ? 'esbuild' : false) : !process.env.DEBUG - } + // important so that each page chunk and the index export things for each + // other + preserveEntrySignatures: 'allow-extension', + output: { + ...rollupOptions?.output, + ...(ssr + ? { + entryFileNames: `[name].js`, + chunkFileNames: `[name].[hash].js` + } + : { + chunkFileNames(chunk) { + // avoid ads chunk being intercepted by adblock + return /(?:Carbon|BuySell)Ads/.test(chunk.name) + ? `assets/chunks/ui-custom.[hash].js` + : `assets/chunks/[name].[hash].js` + }, + manualChunks(id, ctx) { + // move known framework code into a stable chunk so that + // custom theme changes do not invalidate hash for all pages + if (id.includes('plugin-vue:export-helper')) { + return 'framework' + } + if ( + isEagerChunk(id, ctx) && + (/@vue\/(runtime|shared|reactivity)/.test(id) || + /vitepress\/dist\/client/.test(id)) + ) { + return 'framework' + } + } + }) + } + }, + // minify with esbuild in MPA mode (for CSS) + minify: ssr ? (config.mpa ? 'esbuild' : false) : !process.env.DEBUG } - } + }) let clientResult: RollupOutput let serverResult: RollupOutput