'npm pack'时如何包含node_modules

Jay*_*esh 5 npm

我需要在'npm pack'的同时包含一些模块和应用程序..我们是否有任何选项可以将npm模块与应用程序一起包含?

Sai*_*ish 6

在package.json中,我们可以指定在打包时需要捆绑的依赖项列表.

....
  "bundledDependencies": [
    "dependency_1",
    "dependency_2"
]
....
Run Code Online (Sandbox Code Playgroud)

有关bundledDependency的更多详细信息可以在此处找到 .维护此列表可能需要更多手动工作.为此,有一个名为bundle-deps的库

用法

$ bundle-deps [path/to/project]
bundled 48 dependencies.
$ npm pack
// you will see the packaged file contains all your dependencies specified.
Run Code Online (Sandbox Code Playgroud)

  • 根据文档https://docs.npmjs.com/cli/v8/configuring-npm/package-json:__或者,“bundledDependency”可以定义为布尔值。true 值将捆绑所有依赖项, false 值将不捆绑任何依赖项。__ 我们现在可以只编写 "bundleDependencies": true,并且依赖项将全部捆绑 (4认同)