Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emitted chunk in plugin's transform hook lost after rebuild #2929

Closed
edoardocavazza opened this issue Jun 12, 2019 · 7 comments · Fixed by #2933 or #2936
Closed

Emitted chunk in plugin's transform hook lost after rebuild #2929

edoardocavazza opened this issue Jun 12, 2019 · 7 comments · Fixed by #2933 or #2936

Comments

@edoardocavazza
Copy link
Contributor

  • Rollup Version: 1.15.1
  • Operating System (or Browser): MacOS
  • Node Version: 12.3.1

How Do We Reproduce?

Follow the instruction in this repo: https://gitlab.com/edoardo.cavazza/rollup-watch-emit-chunk

Expected Behavior

Emitted chunks in a plugin's transform hook are kept in the bundle cache.

Actual Behavior

Emitted chunks are lost after first build. It works if the chunks are emitted in the load hook.

@lukastaegert
Copy link
Member

lukastaegert commented Jun 12, 2019

Thanks a lot, definitely an oversight. I know we have special logic to handle this case for assets, but I totally forgot about it for chunks. Hope to find some time soon to fix it.

@edoardocavazza
Copy link
Contributor Author

edoardocavazza commented Jun 12, 2019

Thanks @lukastaegert! In the meanwhile, I found out that using the plugin's cache to store transformations and emitted chunks, I can get it properly work re-emitting chunks:

transform(code, id) {
    if (this.cache.has(id)) {
        const { chunks, result, code: previousCode } = this.cache.get(id);
        if (previousCode === code) {
            for (let file in chunks) {
                this.emitChunk(file);
            }
            return result;
        }
    }

    let result = /* transformation result... */;

    this.cache.set(id, {
        code,
        result,
        chunks,
    });

    return result;
}

It's just a workaround, but it works :D

@lukastaegert
Copy link
Member

lukastaegert commented Jun 12, 2019

Fix at #2933

@edoardocavazza
Copy link
Contributor Author

Hi @lukastaegert, I had a test with the new Rollup version, and I noticed that the incremental build works only once. At the secondo rebuild, I still have the original problem...

@lukastaegert
Copy link
Member

Ok, so there is some improvement but not enough. I guess we need to have another go...

@lukastaegert lukastaegert reopened this Jun 13, 2019
@lukastaegert
Copy link
Member

Seems this is also broken for assets, so two issues that might be fixed here together.

@lukastaegert
Copy link
Member

Proper fix that also fixes assets at #2936

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants