search

Home  >  Q&A  >  body text

node.js - Can the package.json of nodejs set the Linux platform not to install a certain dependency?

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 安装完成"
某草草某草草2823 days ago625

reply all(2)I'll reply

  • 天蓬老师

    天蓬老师2017-05-16 13:39:43

    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

    reply
    0
  • 某草草

    某草草2017-05-16 13:39:43

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

    Just indicate it in optionalDependencies

    reply
    0
  • Cancelreply