eight04 / rollup-plugin-iife

Convert ES modules into IIFEs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Annotate with /*#__PURE__*/ magic comment

adi518 opened this issue · comments

commented

This is a cool plugin that can potentially solve a big problem. How can we annotate the IIFE with /*#__PURE__*/?

commented

I don't know what does magic comment do but I guess you have to use the banner option.

commented

It marks a piece of code as pure, making it tree-shakable.

commented

This plugin wraps output bundle to iife. Why do you want to tree-shake the output?

commented

It doesn't do it per export? I imagined it takes every export and wraps it into an IIFE, which I can then mark as pure, that's because without it, some parts of the module aren't detected as pure, such as styleInject calls, which appear in the global scope of the module, thus breaking the tree-shake.

commented

It doesn't do it per export?

No. This plugin modifies output result. Here is an example taken from the test file:

it("output iife", () =>
withDir(`
- entry.js: |
import Emitter from "event-lite";
export default () => new Emitter;
`, async resolve => {
const result = await bundle([resolve("entry.js")], resolve("dist"), {ignoreWarning: [UNRESOLVED_IMPORT]});
assert.equal(result.output["entry.js"].code.trim(), endent`
var entry = (function () {
var entry = () => new eventLite;
return entry;
})();
`);
})
);

Also take a look at es-iife.

it takes every export and wraps it into an IIFE, which I can then mark as pure,

I think the best solution is to use rollup-plugin-shim. There is an example in README that shim debug module with an empty function so all debug function calls will be tree-shaken.

commented

Whoa, I'll go check that out ASAP. Thanks. :)