developit / microbundle

📦 Zero-configuration bundler for tiny modules.
https://npm.im/microbundle
MIT License
8.07k stars 363 forks source link

prevent export merge #1075

Closed orangebokov closed 8 months ago

orangebokov commented 8 months ago

Good afternoon, i'm asking for a little help.

If i have index.ts like this:

export { Monoid } from 'fp-ts/string'
export function sum(a: number, b: number) {
  return a + b;
}

Then bundle index.esm.js will be something like this:

var Monoid = {
    concat: Semigroup.concat,
    empty: empty
};
function sum(a, b) {
  return a + b;
}
export { Monoid, sum };

How to keep exports individual in bundle like this:

export var Monoid = {
    concat: Semigroup.concat,
    empty: empty
};
export function sum(a, b) {
  return a + b;
}

Thank you very much in advance!

rschristian commented 8 months ago

Sorry, what are you after? The last two code blocks are functionally identical.

orangebokov commented 8 months ago

Thanks for the answer.

Then when you import this library into the main project and build the main project using rollup, tree shaking will not work. Because all functions will be stored in one variable. If they are exported separately, tree shaking will remove the unused ones.

P.S. There will be many functions in this library. many of them will not be used. I wish rollup didn't import them.

rschristian commented 8 months ago

Because all functions will be stored in one variable.

That's not what this is.

export { foo, bar } is exporting a list of values, not merging them. You might want to give MDN a skim and brush up on syntax. This is equivalent to what you want, saves a few bytes is all.

This isn't an issue here. If treeshaking isn't working, it's for other reasons.

orangebokov commented 8 months ago

Thank you for paying attention to this. All the best to you.

rschristian commented 8 months ago

No problem, and if you do find an issue w/ Microbundle's output I'd be happy to reopen this & look at it.