npm

how to include node_modules also while 'npm pack'


I need to include some modules along with the application while 'npm pack'.. Do we have any option to include npm modules along with application?


Solution

  • Inside package.json, we can specify list of dependencies that need to be bundled while packaging.

    ....
      "bundledDependencies": [
        "dependency_1",
        "dependency_2"
    ]
    ....
    

    More details on bundledDependency can be found here It may be more manual work to maintain this list. To help this, there is a library called bundle-deps

    Usage

    $ bundle-deps [path/to/project]
    bundled 48 dependencies.
    $ npm pack
    // you will see the packaged file contains all your dependencies specified.
    

    Alternatively, "bundledDependencies" can be defined as a boolean value. A value of true will bundle all dependencies, a value of false will bundle none.

    bundledDependencies documentation