I'm writing a library for Angular2+ users (who would import it before building their own distributions) and to exclude Angular itself from the distribution, I need to do some configuration (in my case include externals
in the Webpack config).
To make this work, according to the Webpack maintainers, I need to assume my library's users use commonjs.
Is it reasonable to assume Angular users use nodejs? Or can we say that whatever bundler/build tool they are using will support nodejs? I don't want to ignore groups of Angular users. What about just releasing the source code? I think assuming TypeScript is safer for Angular2 users than assuming commonjs.
To some extend yes, assuming anything about your library user's environment is bad. However, commonjs is supported by virtually all bundlers. UMD is even better supported (since it is compatible with commonjs and AMD), so that would be a safer bet.
However, with the right config you can support commonjs, esmodules and UMD without much extra config. The difference is in building the first two is done with the TypeScript compiler (reusing the same tsconfig.json), while the UMD distribution is build with Webpack.
Compiling and bundling TypeScript libraries with Webpack explains the setup in details, which includes a demo repo that I forked and completely upgraded, pull request pending.
Aside from this, apparently it is possible to provide AOT build, but I don't know much about that. The only AOT I know is Angular's compiler for precompiling @Components so the browser doesn't have to do it (performance and dist size optimisation).