I have a TypeScript monorepo with PNPM. There are two projects in packages: app and lib.
app depends on lib with PNPM workspace feature. The package.json file of app looks like below, as well as the build script.
{
// ...
"scripts": {
"build": "tsc"
},
"dependencies": {
"@shaunxu/lib": "workspace:^"
}
}
Now I would like to build app and lib into JS to the folder dist/app and dist/lib so that it can be published to NPM registry. If I run pnpm -r build it will compile my TypeScript into JavaScript but the dependencies part of package.json was NOT translated. If I run pnpm -r publish the dependencies part was changed correctly but it pack my TypeScript file.
How can I combine the build (compile) and publish (or dependencies translate) process.
Well I finally figured out this issue. Basically it seems impossible to publish packages from a root-level
distfolder because it out of the workspace range.What we need to do is to build each package into its own
distfolder. For instance we need to buildpackages/libintopackages/lib/distandpackages/appintopackages/app/dist. We also need to copypackage.jsonintodistas well.Then add
publishConfig.directorysection in eachpackage.jsonas below, indicates to pack the files underdistfolder.Now we can use
pnpm -r publishto pack and publish each packages with the workspace part translated.