huozhi / rollup-preserve-directives

This is a rollup plugin that helps preserve shebang and string directives.
https://npmjs.com/package/rollup-preserve-directives
34 stars 4 forks source link

feat: add both default and named export #5

Closed SukkaW closed 1 year ago

SukkaW commented 1 year ago

The default export breaks rollup -c rollup.config.ts --configPlugin swc3 --bundleConfigAsCjs: https://github.com/SukkaW/foxact/actions/runs/5567493053/jobs/10169409656

The PR adds both named export and default export.

huozhi commented 1 year ago

The change is legit but wonder why you have the issue, also saw you’re using esModuleInterop": true, in the tsconfig 🤔️

SukkaW commented 1 year ago

The change is legit but wonder why you have the issue, also saw you’re using esModuleInterop": true, in the tsconfig 🤔️

I don't know, but I guess it is caused by how rollup bundles the rollup.config.ts. It looks like somehow rollup ignores the __esModule convention.

rollup-plugin-dts has the same issue as well: https://github.com/Swatinem/rollup-plugin-dts/issues/247

huozhi commented 1 year ago

Ah looks like the official plugins are using a trick like https://github.com/rollup/plugins/blob/5ec2abe0325ed6b23bca26a5455d2a3b137e9e29/shared/rollup.config.mjs#L28

Which we don't have it, and --bundleConfigAsCjs makes it resolved as cjs. Does it work if you remove that flag?