npm install : 指定 package.json? [英] npm install : specify 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屋!