I have a Next.js application, which not only has pages, but also some components. These components are written in TypeScript (so we're essentially talking .tsx here), and they use CSS Modules, using Next.js's *.module.css pattern – or, to be more precise, they use CSS Modules combined with Next.js's SASS support, so we're talking *.module.sass here. So far, everything works fine.
Now I would like to create a second Next.js app, and I need some of the components in both applications. Of course, I could copy / paste them, but this is a bad idea for obvious reasons. What I would like to do is to extract the shared components into an npm module of their own, and use that in both applications. Now this is the tricky part.
I don't want to precompile the shared code, to allow the respective Next.js application to do the compilation for the application code and the UI library code, but I don't know how to accomplish this. Of course, it's easy to setup an npm module which just contains plain *.tsx and *.module.sass files, but how do I make the final Next.js application compile them, too?
AFAICS Next.js only compiles components and styles that are contained in the application itself, not those defined in modules installed via npm. Is there any way to enable this?
PS: I'm aware of the next-transpile-modules module, but I'd rather prefer a somewhat more "official" approach, if there is any…