histoire
Version:
A fast story book powered by Vite
37 lines (36 loc) • 1.96 kB
JavaScript
import { version as viteVersion } from 'vite';
import { isLazyBrowserDependency } from './lazy-dependencies.js';
import { hasVendorDependencyClosure } from './vendor-graph.js';
/** Preserve portable data and lazy engines while sharing dependency-closed vendors. */
export function createBuildChunkOutput(ctx) {
const embedEnabled = ctx.config.embed?.enabled ?? false;
/** Portable data must never inherit Vue or standalone UI side effects. */
const isEmbedData = (id) => embedEnabled && (id.includes('@histoire/protocol') || id.includes('/histoire-protocol/') || id.includes('/fuse.js/'));
/** Generated project imports cannot safely join a shared framework chunk. */
const isVendorCandidate = (id) => !isLazyBrowserDependency(id) && !isEmbedData(id)
&& !id.includes('@histoire/app') && id.includes('node_modules')
&& !(ctx.config.build?.excludeFromVendorsChunk ?? []).some(test => typeof test === 'string' ? id.includes(test) : test.test(id));
/** Missing or project-owned dependencies keep their natural execution boundaries. */
function classify(id, graph) {
if (isLazyBrowserDependency(id))
return;
if (isEmbedData(id))
return 'embed-data';
if (hasVendorDependencyClosure(id, moduleId => graph.getModuleInfo(moduleId), isVendorCandidate))
return 'vendor';
}
if (Number.parseInt(viteVersion, 10) < 8) {
return { onlyExplicitManualChunks: true, manualChunks: classify };
}
return {
codeSplitting: {
// Never absorb Vite helpers or lazy engines through recursive chunk capture.
includeDependenciesRecursively: false,
groups: [{
debugName: 'histoire-shared',
/** Rolldown supplies dependency lookups without whole-graph enumeration. */
name: (id, graph) => classify(id, graph) ?? null,
}],
},
};
}