Skip to content

Commit 89e1666

Browse files
authored
fix: Ensure user can configure manualChunks w/out issue (#7)
1 parent fd4f3ef commit 89e1666

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/plugins/prerender-plugin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ export function prerenderPlugin({ prerenderScript, renderTarget, additionalPrere
124124
Array.isArray(config.build.rollupOptions.output) ||
125125
config.build.rollupOptions.output?.manualChunks
126126
) {
127+
viteConfig = config;
127128
return;
128129
}
129130

tests/index.test.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import path from 'node:path';
44
import { promises as fs } from 'node:fs';
55

66
import { 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

911
let env;
1012
test.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+
3267
test.run();

0 commit comments

Comments
 (0)