I am eager to publish my TypeScript project on NPM. I am currently using the TypeScript Compiler (tsc) to transpile the .ts files of my project into output .js file(s).
To generate the output files, I simply use the tsc
command.
Here is my tsconfig.json:
{
"compilerOptions": {
"outDir": "dist",
"declaration": true,
"module": "commonjs",
"moduleResolution": "node",
"target": "es5"
}
}
Once published, my package can be installed using:
npm install mypackagename
and can be imported in TypeScript like so:
import MyLib from 'mypackagename'
It works! However, I am interested in offering two types of installations: through npm/import (as shown above) and via CDN:
<script src="//unpkg.com/mypackagename"></script>
Is this possible? Do I need to utilize a bundler instead of the TypeScript Compiler?
Currently, it seems impossible as I am unable to directly use commonjs code in a browser.