Skip to content

Commit

Permalink
fix: Ensure user can configure manualChunks w/out issue (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
rschristian authored Jan 21, 2025
1 parent fd4f3ef commit 89e1666
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/plugins/prerender-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export function prerenderPlugin({ prerenderScript, renderTarget, additionalPrere
Array.isArray(config.build.rollupOptions.output) ||
config.build.rollupOptions.output?.manualChunks
) {
viteConfig = config;
return;
}

Expand Down
37 changes: 36 additions & 1 deletion tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import path from 'node:path';
import { promises as fs } from 'node:fs';

import { setupTest, teardownTest, loadFixture, viteBuild } from './lib/lifecycle.js';
import { getOutputFile } from './lib/utils.js';
import { getOutputFile, writeFixtureFile } from './lib/utils.js';

const writeConfig = async (dir, content) => writeFixtureFile(dir, 'vite.config.js', content);

let env;
test.before.each(async () => {
Expand All @@ -21,12 +23,45 @@ test('Should prerender and output correct file structure', async () => {

const prerenderedHtml = await getOutputFile(env.tmp.path, 'index.html');
assert.match(prerenderedHtml, '<h1>Simple Test Result</h1>');
});

test('Should merge preload and entry chunks', async () => {
await loadFixture('simple', env);
await viteBuild(env.tmp.path);

const outDir = path.join(env.tmp.path, 'dist');
const outDirAssets = path.join(outDir, 'assets');

assert.equal((await fs.readdir(outDir)).length, 2);
// Would be 2 if not merged
assert.equal((await fs.readdir(outDirAssets)).length, 1);
});

test('Should bail on merging preload & entry chunks if user configures `manualChunks`', async () => {
await loadFixture('simple', env);
await writeConfig(env.tmp.path, `
import { defineConfig } from 'vite';
import { vitePrerenderPlugin } from 'vite-prerender-plugin';
export default defineConfig({
build: {
rollupOptions: {
output: {
manualChunks: {}
}
}
},
plugins: [vitePrerenderPlugin()],
});
`);

await viteBuild(env.tmp.path);

const outDir = path.join(env.tmp.path, 'dist');
const outDirAssets = path.join(outDir, 'assets');

assert.equal((await fs.readdir(outDir)).length, 2);
assert.equal((await fs.readdir(outDirAssets)).length, 2);
});

test.run();

0 comments on commit 89e1666

Please sign in to comment.