How to bundle dependencies in npm package?

2019-06-02 08:09发布

问题:

I have a npm package which reference an other local package. It has a structure like so.

  • deploy
    • typescriptapp.tgz
  • references
    • mydependency
      • package.json
      • app.js
      • app.css
  • typescriptapp
    • package.json
  • webapp

My typescriptapp package.json has the following dependencies

  "dependencies": {
    "mydependency": "file:../references/mydependency"
  },

My webapp package.json has the following dependencies

  "dependencies": {
    "typescriptapp": "file:../deploy/typescriptapp-1.0.0.tgz"
  },

When I use npm pack it work fine, but it is not included in the tarball. I also move the tarball to a deploy folder

When I try npm install, it doesn't work because the reference folder does not exist in the deploy folder.

I also tried to change the dependencies for bundledDependencies

  "bundledDependencies": [
    "file:../references/mydependency"
  ]

But it does not seem to work either.

How do I pack my typescript app to be able to install it in my webapp with a single file?