Skip to content

Commit 7999843

Browse files
authored
fix(legacy): use prebuilt-chunk for polyfill chunks (#21498)
1 parent b68900b commit 7999843

4 files changed

Lines changed: 18 additions & 14 deletions

File tree

docs/guide/migration.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,6 @@ The following options are deprecated and will be removed in the future:
342342
These breaking changes are expected to only affect a minority of use cases:
343343

344344
- **[TODO: this will be fixed before stable release]** https://github.com/rolldown/rolldown/issues/5726 (affects nuxt, qwik)
345-
- **[TODO: this will be fixed before stable release]** Legacy chunks are emitted as an asset file instead of a chunk file due to the lack of prebuilt chunk emit feature ([rolldown#4304](https://github.com/rolldown/rolldown/issues/4034)). This means the chunk related options does not apply to legacy chunks and the manifest file will not include legacy chunks as a chunk file.
346345
- **[TODO: this will be fixed before stable release]** `@vite-ignore` comment edge case ([rolldown-vite#426](https://github.com/vitejs/rolldown-vite/issues/426))
347346
- [Extglobs](https://github.com/micromatch/picomatch/blob/master/README.md#extglobs) are not supported yet ([rolldown-vite#365](https://github.com/vitejs/rolldown-vite/issues/365))
348347
- `define` does not share reference for objects: When you pass an object as a value to `define`, each variable will have a separate copy of the object. See [Oxc Transformer document](https://oxc.rs/docs/guide/usage/transformer/global-variable-replacement#define) for more details.

packages/plugin-legacy/src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -900,9 +900,16 @@ async function buildPolyfillChunk(
900900

901901
// add the chunk to the bundle
902902
ctx.emitFile({
903-
type: 'asset',
903+
type: 'prebuilt-chunk',
904+
name: polyfillChunk.name,
904905
fileName: polyfillChunk.fileName,
905-
source: polyfillChunk.code,
906+
code: polyfillChunk.code,
907+
facadeModuleId: polyfillChunk.facadeModuleId ?? undefined,
908+
isEntry: polyfillChunk.isEntry,
909+
isDynamicEntry: polyfillChunk.isDynamicEntry,
910+
exports: [],
911+
map: polyfillChunk.map ?? undefined,
912+
sourcemapFileName: polyfillChunk.sourcemapFileName ?? undefined,
906913
})
907914
if (polyfillChunk.sourcemapFileName) {
908915
const polyfillChunkMapAsset = _polyfillChunk.output.find(

playground/legacy/__tests__/legacy.spec.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,10 @@ describe.runIf(isBuild)('build', () => {
8686
test('should generate correct manifest', async () => {
8787
const manifest = readManifest()
8888
// legacy polyfill
89-
// FIXME: needs https://github.com/rolldown/rolldown/issues/4034
90-
// expect(manifest['../../vite/legacy-polyfills-legacy']).toBeDefined()
91-
// expect(manifest['../../vite/legacy-polyfills-legacy'].src).toBe(
92-
// '../../vite/legacy-polyfills-legacy',
93-
// )
89+
expect(manifest['../../vite/legacy-polyfills-legacy']).toBeDefined()
90+
expect(manifest['../../vite/legacy-polyfills-legacy'].src).toBe(
91+
'../../vite/legacy-polyfills-legacy',
92+
)
9493
expect(manifest['custom0-legacy.js'].file).toMatch(
9594
/chunk-X-legacy\.[-\w]{8}.js/,
9695
)
@@ -101,11 +100,10 @@ describe.runIf(isBuild)('build', () => {
101100
/chunk-X-legacy[-\w]{8}.js/,
102101
)
103102
// modern polyfill
104-
// FIXME: needs https://github.com/rolldown/rolldown/issues/4034
105-
// expect(manifest['../../vite/legacy-polyfills']).toBeDefined()
106-
// expect(manifest['../../vite/legacy-polyfills'].src).toBe(
107-
// '../../vite/legacy-polyfills',
108-
// )
103+
expect(manifest['../../vite/legacy-polyfills']).toBeDefined()
104+
expect(manifest['../../vite/legacy-polyfills'].src).toBe(
105+
'../../vite/legacy-polyfills',
106+
)
109107
})
110108

111109
test('should minify legacy chunks with terser', async () => {

playground/legacy/__tests__/watch/legacy-styles-only-entry-watch.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test.runIf(isBuild)('rebuilds styles only entry on change', async () => {
1717
)
1818
expect(findAssetFile(/polyfills-legacy-.+\.js/, 'watch')).toBeTruthy()
1919
const numberOfManifestEntries = Object.keys(readManifest('watch')).length
20-
expect(numberOfManifestEntries).toBe(2) // FIXME: needs https://github.com/rolldown/rolldown/issues/4034
20+
expect(numberOfManifestEntries).toBe(3)
2121

2222
editFile('style-only-entry.css', (originalContents) =>
2323
originalContents.replace('#ff69b4', '#ffb6c1'),

0 commit comments

Comments
 (0)