npm install : 指定 package.json? [英] npm install : specify package.json?

查看:169
本文介绍了npm install : 指定 package.json?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在运行npm install"时告诉 npm 使用另一个 package.json ?

How can I tell npm to use another package.json when running "npm install" ?

我需要的只是 npm install -f packages-win32.json 或者是否有技巧或其他方法可以实现相同的目标?

All I need is npm install -f packages-win32.json Or is there a trick or another approach to achieve the same?

因为并非所有 npm 模块都是跨平台的,我想在每个平台上使用其他包.

Because not all npm modules are cross-platform and I'd like to use other packages per platform.

推荐答案

您不能指定不同的 package.json 文件,因为规范实际上仅适用于名为 package.json.

You cannot specify a different package.json file as the specs are literally only for a file called package.json.

如果您对仅适用于任一操作系统的软件包有一些问题,请尝试使用

If you have some issues with packages that only work on either os try them out with

try {
  thing = require('thing');
}
catch( error ) {
  thing = require('other');
}

您还可以通过以下方式嗅探操作系统:

You can also sniff out the os via:

const _isWin = /^win/.test( process.platform );

或者使用 os.platform() 如果你不需要支持 node <= 5...

Or use os.platform() if you don't have to support node <= 5...

也许这有帮助?

这篇关于npm install : 指定 package.json?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆