Skip to content

Comments

feat: this.emitFile support prebuilt-chunk type#4990

Merged
lukastaegert merged 10 commits intorollup:masterfrom
TrickyPi:feat/emitfile-xiaopi
May 22, 2023
Merged

feat: this.emitFile support prebuilt-chunk type#4990
lukastaegert merged 10 commits intorollup:masterfrom
TrickyPi:feat/emitfile-xiaopi

Conversation

@TrickyPi
Copy link
Member

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:
resolves #4210

Description

This PR implements a basic feature about emitting prebuilt chunks, outlined in #4210 (comment)

@vercel
Copy link

vercel bot commented May 13, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
rollup ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 22, 2023 4:52am

@codecov
Copy link

codecov bot commented May 13, 2023

Codecov Report

Merging #4990 (abaafeb) into master (0ee31f1) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head abaafeb differs from pull request most recent head 28be756. Consider uploading reports for the commit 28be756 to get more accurate results

@@           Coverage Diff           @@
##           master    #4990   +/-   ##
=======================================
  Coverage   98.97%   98.97%           
=======================================
  Files         222      222           
  Lines        8157     8175   +18     
  Branches     2243     2250    +7     
=======================================
+ Hits         8073     8091   +18     
  Misses         30       30           
  Partials       54       54           
Impacted Files Coverage Δ
src/utils/FileEmitter.ts 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! However, we need some more tests, and then we need to update the documentation.

@TrickyPi
Copy link
Member Author

Thanks for your review! I'll update the documentation tomorrow.

@TrickyPi
Copy link
Member Author

docs has been updated.

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I slightly changed the wording of the docs, but overall I will release this now.

@lukastaegert lukastaegert merged commit 06e9045 into rollup:master May 22, 2023
@rollup-bot
Copy link
Collaborator

This PR has been released as part of [email protected]. You can test it via npm install rollup.

@TrickyPi TrickyPi deleted the feat/emitfile-xiaopi branch May 23, 2023 06:19
shulaoda added a commit to rolldown/rolldown that referenced this pull request Dec 4, 2025
Implements `emitFile({ type: 'prebuilt-chunk', ... })` for Rollup API
compatibility, allowing plugins to emit pre-built chunks directly to the
bundle output. See
https://rollupjs.org/plugin-development/#this-emitfile and
rollup/rollup#4990

### Changes

**TypeScript**
- Added `EmittedPrebuiltChunk` interface with `fileName`, `code`,
`exports?`, `map?`, `sourcemapFileName?`
- Updated `emitFile` in plugin context to handle prebuilt-chunk type
- Exported `EmittedPrebuiltChunk` from package index

**Rust**
- Added `EmittedPrebuiltChunk` struct and `prebuilt_chunks` storage in
`FileEmitter`
- Implemented `emit_prebuilt_chunk` method
- Updated `get_file_name` and `add_additional_files` to support prebuilt
chunks

**Bindings**
- Added `BindingEmittedPrebuiltChunk` NAPI struct
- Added `emit_prebuilt_chunk` to `BindingPluginContext`

### Usage

```typescript
const plugin = {
  name: 'emit-prebuilt',
  buildStart() {
    const refId = this.emitFile({
      type: 'prebuilt-chunk',
      fileName: 'vendor.js',
      code: 'console.log("prebuilt");',
      exports: ['default'],
    });
    // this.getFileName(refId) => 'vendor.js'
  },
};
```

<!-- START COPILOT CODING AGENT SUFFIX -->



<details>

<summary>Original prompt</summary>

> 
> ----
> 
> *This section details on the original issue you should resolve*
> 
> <issue_title>[Feature Request]: Support emit prebuilt
chunk</issue_title>
> <issue_description>
> [\[Feature Request\]: Support emit prebuilt chunk · Issue
#4034 ·
rolldown/rolldown](https://github.com/rolldown/rolldown/issues/4034)</issue_description>
> 
> ## Comments on the Issue (you are @copilot in this section)
> 
> <comments>
> <comment_new><author>@Boshen</author><body>
> Plugin-legacy does not strictly require this, we have a draft PR
https://github.com/vitejs/rolldown-vite/pull/80</body></comment_new>
> </comments>
> 


</details>

- Fixes #4034

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in
our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

Co-authored-by: shulaoda <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide an way to modify Emited chunk in generateBundle | writeBundle hooks

3 participants