-
-
Notifications
You must be signed in to change notification settings - Fork 32
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
targeting CJS and ESM modules #107
Comments
Hey there. To my understanding, if you want to generate // source
export = function myFunction(...) {
...
} If you write However, I don't think there's any way around this without allowing targeting CommonJS internally which would lead to the plugin passing back CommonJS modules to Rollup, but this is to be avoided at all costs. I'm aware of this problem and thinking about potential workarounds. But unfortunately this isn't possible as of yet. |
@wessberg sounds like, as silly as it is, a string replacement as a last step isn't the worst possible decision for me? |
Feel free to do so, if that solves the problem for you |
@bcoe you can try using the package I've recently made for this use case: https://github.com/axtgr/ts-transform-default-export Adding it in your import ts from "@wessberg/rollup-plugin-ts";
import transformDefaultExport from "ts-transform-default-export";
export default {
...
plugins: [
ts({
transformers: ({ program }) => ({
afterDeclarations: transformDefaultExport(program),
}),
}),
],
}; It's apparently even possible to use this combination to make Rollup produce both CJS and ESM bundles and a single declaration file that is compatible with both of them, possibly solving the problem mentioned by @wessberg. The declaration will have |
@axtgr looks like a great solution, and a great use case for Custom Transformers! 🙂 |
@axtgr thank you 😄 I prefer this to my hacky replace logic. |
Question
Hello @wessberg, first of thank you for the wonderful utility, this helped unblock my project to target ESM/CJS with yargs-parser 💯
Here's what I'm tying to figure out. I've created a module that uses
tsc
to target ESM, and usesrollup-plugin-ts
to target CJS.In my index I have:
This works well for my compilation to ESM, which maintains the same export, but I end up with the following syntax when using
rollup-plugin-ts
:I would rather than the export be:
As I believe this is the best way to keep
yargs-parser
's existing API surface.Is there a configuration setting that would facilitate this?
The text was updated successfully, but these errors were encountered: