2

I'm trying to find out how to configure SWC in a way that builds the applications inside my monorepo with the source code from my libs directory, like I used to do with webpack (although much much much slower).

I've tried various combinations with paths in tsconfig.json and the paths in the .swcrc without any luck, whatever I do, the dist directory code merely references the code inside the libs directory exactly as I reference it in my source code as if it were a compiled node-module.

I have created a minimum-reproduction repository with instructions in the readme:

https://github.com/sebastiangug/nest-nx-swc

expected behaviour

SWC bundles the code at libs/config and libs/database etc. together with the project source code at services/monolith/src

observed behaviour:

SWC throws cannot find module '../../../libs/config/config.module' with the compiled files in dist referencing these as a relative import to the TS source code.

with webpack, it would be the case that the whole code would get compiled into the final artifact inside dist without needing to build libraries separately.


I've also tried to configure importing via alias from @lib with an index.ts re-exporting modules from libs, this works fine with typescript and tsconfig but the bundler then can't find where @lib is even with its paths and baseUrl configured accordingly.

0