isaacs / tshy

Other
894 stars 18 forks source link

Excluding Files from Build, Targeted Builds #59

Closed shellscape closed 6 months ago

shellscape commented 6 months ago

I've got a project where I have to build artifacts in the same src directory: the primary module, and the CLI for the module. The ideal setup is that the primary module is compiled to both commonjs and esm, but the CLI is built only with esm (as the "bin" property in package.json references only the esm build). Right now, tshy is attempting to include the CLI in the commonjs output and it's throwing all kinds of errors like:

The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("vite")' call instead.

I don't want tshy to consider commonjs for the CLI at all. How can this be accomplished with tshy?

shellscape commented 6 months ago

OK I totally missed this in the docs: https://github.com/isaacs/tshy?tab=readme-ov-file#excluding-from-a-build-using-cts-and-mts-files

If that's the correct method, please close this one.

isaacs commented 6 months ago

Yup! Just name it .mjs and it'll only be esm.