node.js - Can the package.json of nodejs set the Linux platform not to install a certain dependency?
某草草
某草草 2017-05-16 13:37:43
0
2
581

For example, I want to install a certain module on both mac and win, but not install a certain module on the linux platform. How to set it up? Is it possible?


Replenish

I finally found that it can be done using shell script

#!/bin/bash
echo "正在安装 electron ……"
npm install electron-prebuilt@1.2.1
echo "electron 安装完成"


echo "正在安装 async ……"
npm install async@2.0.1
echo "async 安装完成"
某草草
某草草

reply all(2)
Peter_Zhu

package.jsonI don’t know if it can be done, but it can be implemented using a script.

// index.js
const exec = require('child_process').exec

const platform = process.platform;

switch(platform) {
case 'darwin':
  // mac
  break;
case 'linux': 
  exec('npm install XXX')
  break;
case 'win32':
  break;
}

node index.js Now you can install XXX

某草草

https://docs.npmjs.com/files/...

Just indicate it in optionalDependencies

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template