@@ -4,7 +4,9 @@ import path from 'node:path';
44import { promises as fs } from 'node:fs' ;
55
66import { setupTest , teardownTest , loadFixture , viteBuild } from './lib/lifecycle.js' ;
7- import { getOutputFile } from './lib/utils.js' ;
7+ import { getOutputFile , writeFixtureFile } from './lib/utils.js' ;
8+
9+ const writeConfig = async ( dir , content ) => writeFixtureFile ( dir , 'vite.config.js' , content ) ;
810
911let env ;
1012test . before . each ( async ( ) => {
@@ -21,12 +23,45 @@ test('Should prerender and output correct file structure', async () => {
2123
2224 const prerenderedHtml = await getOutputFile ( env . tmp . path , 'index.html' ) ;
2325 assert . match ( prerenderedHtml , '<h1>Simple Test Result</h1>' ) ;
26+ } ) ;
27+
28+ test ( 'Should merge preload and entry chunks' , async ( ) => {
29+ await loadFixture ( 'simple' , env ) ;
30+ await viteBuild ( env . tmp . path ) ;
2431
2532 const outDir = path . join ( env . tmp . path , 'dist' ) ;
2633 const outDirAssets = path . join ( outDir , 'assets' ) ;
2734
2835 assert . equal ( ( await fs . readdir ( outDir ) ) . length , 2 ) ;
36+ // Would be 2 if not merged
2937 assert . equal ( ( await fs . readdir ( outDirAssets ) ) . length , 1 ) ;
3038} ) ;
3139
40+ test ( 'Should bail on merging preload & entry chunks if user configures `manualChunks`' , async ( ) => {
41+ await loadFixture ( 'simple' , env ) ;
42+ await writeConfig ( env . tmp . path , `
43+ import { defineConfig } from 'vite';
44+ import { vitePrerenderPlugin } from 'vite-prerender-plugin';
45+
46+ export default defineConfig({
47+ build: {
48+ rollupOptions: {
49+ output: {
50+ manualChunks: {}
51+ }
52+ }
53+ },
54+ plugins: [vitePrerenderPlugin()],
55+ });
56+ ` ) ;
57+
58+ await viteBuild ( env . tmp . path ) ;
59+
60+ const outDir = path . join ( env . tmp . path , 'dist' ) ;
61+ const outDirAssets = path . join ( outDir , 'assets' ) ;
62+
63+ assert . equal ( ( await fs . readdir ( outDir ) ) . length , 2 ) ;
64+ assert . equal ( ( await fs . readdir ( outDirAssets ) ) . length , 2 ) ;
65+ } ) ;
66+
3267test . run ( ) ;
0 commit comments