在执行'npm pack'命令时,我需要将一些模块与应用程序一起包含。我们是否有选项可以将npm模块与应用程序一起包含?
在执行'npm pack'命令时,我需要将一些模块与应用程序一起包含。我们是否有选项可以将npm模块与应用程序一起包含?
在 package.json 文件中,我们可以指定需要在打包时捆绑的依赖项列表。
....
"bundledDependencies": [
"dependency_1",
"dependency_2"
]
....
有关bundledDependency的更多详细信息,请点击此处查看。
维护此列表可能需要更多手动工作。为了帮助解决这个问题,有一个名为bundle-deps的库可用。
用法
$ bundle-deps [path/to/project]
bundled 48 dependencies.
$ npm pack
// you will see the packaged file contains all your dependencies specified.
或者,“bundledDependencies”可以定义为布尔值。 true的值将捆绑所有依赖项,false的值将不捆绑任何依赖项。
bundleDependencies
是 npm 8 中默认的字段名,但bundledDependencies
仍然有效。 - Marc Durdin