如何在受限制的互联网访问环境中使用npm

在不是每个用户都有权访问的受限环境中,我希望能够在任何可能的情况下脱机使用npm。

我的想法是将全局configuration指向一个共享的caching目录,以便高级用户可以进行安装,并且依赖关系将在caching目录中结束。 然后,其他用户可以执行npm脱机安装以前在caching中的任何内容。

所以2个问题:

这会工作吗? build立我自己的本地npm仓库是否有一个更简单的方法?

每个文档:

npm install (with no args in a package dir) npm install <tarball file> npm install <tarball url> npm install <folder> npm install <name> [--save|--save-dev|--save-optional] npm install <name>@<tag> npm install <name>@<version> npm install <name>@<version range> npm i (with any of the previous argument usage) 

因此,npm允许你做:

npm install /path/to/folder/containing/ contained npm install /path/to/folder/containing/ node_modules

例如: npm install ~/Downloads/http-proxy node_modules npm install ~/Downloads/http-proxy ,前提是node_modules文件夹驻留在http-proxy

你可以在一个内部(可访问)的服务器上设置你的仓库,并指导人们从那里下载相同的名字。

感谢您的答案。 我最终做的是使用https://github.com/rlidwka/sinopia

这充当镜像存储库。 我可以给这个过程上网,而不是其他用户。 然后,我为所有用户设置一个环境variables,将它们的npm存储库指向sinopia实例。

早期,但这似乎运作良好。

r3mus是对的。 但是,对于每个用户来说,这会导致一些认知开销和可能的pipe理问题。

有什么更好的办法是有一个企业托pipenpm存储库(如在这里描述: http : //clock.co.uk/tech-blogs/how-to-create-a-private-npmjs-repository ),然后只是有用户通过npm set registry http://yourregistry.com更改(一次)他们的registry设置

对于构build服务器,合理的策略是将node_modules目录与已安装模块的现有目录进行符号链接。

例如我的powershell脚本可能会读这样的东西

 If (-Not (Test-Path node_modules)) { & cmd /c mklink /d /j node_modules D:\npm-cache\node_modules Write-Verbose "Symlinked node_modules" }