This week was less productive due to conainment and I spent my time to struggle on how to compile a TS package for NPM and browser whithin a single file.
To be quick, here are the two most important thing I found:
I use Rollup to compile my TS in a single file.
It is straigh forward and really 0 config. My main issue is that I used a monorepo and one of my package used another one.
In this case you have too start your script in the root folder of your monorepo. Otherwize you will end with: "Debug Failure. False expression: Expected fileName to be present in command line"
My main file exports explicitely each end point of my API.
It is the most important thing that I learnt because Rollup will reduce your package as a single file, but the declaration files will mirror your source hierarchy.
This will result in a "myModule is not a module" error when you will consume the package.
To fix this, you "just" need to write your main entry file like this:
export {
string,
number,
boolean,
undefinedType,
unknown,
array,
object,
map,
reference,
identifier,
component,
} from "./ravioli"
It is tedious but note that is the occasion to clean your code and export only what is needed (instead of export everything "just in case"). You minified code will be smaller (because exported things are not rewritted by the minimifier)
Top comments (0)