developit / microbundle

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

Wrong formats and broken type definitions #836

Closed DaSchTour closed 3 years ago

DaSchTour commented 3 years ago

To but it mildly I'm extremely confused. For a zero configuration bundler there is a lot to do to make it work, while actually it's completely broken.

Typescript definitions are missing files that only include interfaces which leads to broken type definitions.

The esm format is actually not a module format but also just a bundle. I would have expected to see a low transpiled code that can be picked up by another bundler when it is imported as a library in another project.

I would also expect it not to be minified if it's a module format and that it also is not put into one file but actually preserve the module structure.

When using "type": "module" and "main": "./dist/index.cjs", as described in the README all bundles are named index.cjs.js, index.cjs.umd.js and so on. So all references in the package.json are wrong.

developit commented 3 years ago

Can you clarify what TypeScript definition you're talking about? This is a CLI, I can't think of how TS has any relevance to it.

The ESM output format generates bundles that use import and export, which is very much ES Modules. It's not clear to me what your expectation was - if a bundler did not bundle code, it wouldn't be a bundler.

Microbundle is explicitly designed to produce minified output - that is effectively the entire premise of the project. Minification can be turned off using the --no-minify option, but doing this essentially reduces Microbundle to an unnecessary abstraction around Rollup.

The CJS thing is a bug that has already been fixed - the docs were updated some time in the last two weeks, but we haven't cut a release yet with the corresponding changes.

It sounds like you are looking for a Rollup configuration and do not want to bundle or minify, in which case Microbundle is simply the wrong tool for the job.

DaSchTour commented 3 years ago

Yeah, I see. I wonder why there is this unfilled gap between rollup and a bundler. In fact what I see is that microbundle is also only an abstraction around Rollup. And if microbundle only adds the minification I don't get the purpose 😄

developit commented 3 years ago

To each their own! The purpose of abstractions like Microbundle is the same as any other abstraction: instead of copy-and-pasting nearly-identical Rollup configurations into each npm module one maintains, the abstraction allows each project to depend on a centralized configuration that can be updated over time without having to manually copy changes between projects.

rhyek commented 3 years ago

When using "type": "module" and "main": "./dist/index.cjs", as described in the README all bundles are named index.cjs.js, index.cjs.umd.js and so on.

Is there a workaround for this? I tried removing "type": "module", but it still happens. I notice that the latest version is from December so I'm wondering if I should use a previous version or if there might be a better solution.

Thanks.

agilgur5 commented 2 years ago

Typescript definitions are missing files that only include interfaces which leads to broken type definitions.

Thought I'd update here that I fixed the root cause of this type-only issue upstream in https://github.com/ezolenko/rollup-plugin-typescript2/pull/406, which was released in rpt2 0.34.0