Open ajwootto opened 10 months ago
@ajwootto Excuse me, is there a workaround when using rollup
bundler for a next
library?
@potouridisio not sure, but I filed a separate issue for it
This issue has been automatically marked as stale because it hasn't had any activity for 6 months. Many things may have changed within this time. The issue may have already been fixed or it may not be relevant anymore. If at this point, this is still an issue, please respond with updated information. It will be closed in 21 days if no further activity occurs. Thanks for being a part of the Nx community! 🙏
not stale
Description
Executors such as
tsc
should be able to output a module inESM
orCommonjs
according to executor settings in project.json. Similar to therollup
executor, it should support aformats
field that also allows "hybrid" packages to be produced by specifying both ESM and commonjs.Motivation
Currently the only way to make a "hybrid" package with Nx is using the
Rollup
executor, but it is often the case that a library author doesn't want to bundle the files together when distributing the library. One current reason for "why" is that bundlers remove"use client"
directives needed to distribute React client component libraries: https://github.com/nrwl/nx/issues/19714Another is that bundling should be the responsibility of the consumer of a library, it doesn't really make sense to "pre-bundle" files that only really need to be bundled if they are going into an application bundle, in which case another bundler is already going to be in use.
Also as noted in the TS docs, type checking of source files is only applied using one of the two module systems, and using a 3rd party bundler like Rollup to generate two kinds of output means that only one of them is being type checked. https://www.typescriptlang.org/docs/handbook/modules/guides/choosing-compiler-options.html#notes-on-dual-emit-solutions Using
tsc
for both kinds of output would allow the build to fail if either of those kinds of output is invalid.Suggested Implementation
End-user option could look the same as the
rollup
one, withformats
allowing multiple formats to be listed. Under the hood, I'd imagine it would runtsc
twice while overriding the "module" setting for one of the builds, and then properly structure thepackage.json
output to be a hybrid package.Alternate Implementations