NPM build package after install

Viewed 354

I made a package with react and typescript. Because of how typescript handles the publishing of the classes and interfaces, I need to build the package and commit the built files with every change. Is there a way to tell npm, that it has to build the specific package after "npm install" or "yarn install"?

I tried adding "postinstall": "npm run build" and "prepare": "npm run build" but it seems, that the project, in which the package is installed, runs this commands in his own root directory, so it builds itself, instead of just the package.

I thought of something like this:

  1. Coding in a project
  2. yarn add packageX
  3. yarn install
  4. packageX runs npm run build in its own directory
  5. make changes in packageX
  6. run yarn update packageX
  7. packageX runs npm run build in its own directory
  8. run yarn build in project root
  9. Project builds itself

Is there a way to accomplish that?

Thanks for your answers.

0 Answers
Related