Rollup preserveEntrySignatures behavior across major versions
0 reputation · 11 Apr 2021, 17:05 UTC
0 reputation · 11 Apr 2021, 17:05 UTC
Goal: emit an existing application bundle and a replacement bundle from one Rollup build, serve both from the same origin without server downtime, and load the new entry only for selected routes using dynamic import().
Constraint: preserveEntrySignatures controls whether an entry point re-exports all chunk exports, only its own exports, allows extension, or disables preservation. The default and exact export semantics changed across Rollup major versions, making entry-point compatibility version-sensitive. External dependencies stay unresolved and must be provided at runtime, which affects whether esm, cjs, or iife output suits the migration target. Rollup does not switch traffic between bundles.
35275 reputation · 12 Apr 2021, 01:39 UTC
To keep the old entry’s public API unchanged while exposing a new entry with only its own exports, use preserveEntrySignatures as an object mapping: { oldEntry: 'strict', newEntry: 'exports-only' }. The exact default depends on your Rollup major version.
false (no preservation). Each entry emits only its own exports; chunk exports are not re‑exported.'strict' (preserve entry signatures). Each entry re‑exports all exports from its chunks, matching the entry‑point’s original API.preserveEntrySignatures is supported starting with Rollup 2.1. Earlier versions accept only a single global value, requiring separate builds or a workaround.external option (e.g., external: ['lodash', 'react']) and supplied at runtime via a shared global, import map, or UMD/IIFE wrapper. Using the same output format for both bundles prevents duplicate loads and version conflicts.npm list rollup or rollup --version.preserveEntrySignatures: false (default) for both entries.preserveEntrySignatures: true via a plugin.preserveEntrySignatures as an object:
export default {
input: {
oldApp: './src/old-entry.js',
newApp: './src/new-entry.js'
},
output: [
{ format: 'esm', dir: 'dist', entryFileNames: '[name].js' }
],
external: ['lodash', 'react'],
preserveEntrySignatures: {
oldApp: 'strict', // keeps original API (re‑exports chunk exports)
newApp: 'exports-only' // exposes only its own declarations
}
};
rollup -c.dist/oldApp.js should contain re‑exports from chunks; dist/newApp.js should only contain its own exports.window global or an import map) and ensure both bundles use the same format (ESM with import maps, UMD, or IIFE).The recommendation differs between Rollup 1 and Rollup 2+; please confirm your exact Rollup major version so the steps can be finalized.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.