简体   繁体   中英

node.js - how to install a single dependency globally?

My package.json file looks like this:

{
  "name": "tets",
  "version": "1.0.0",
  "devDependencies": {
    "chai": "^3.0.0",
    "gulp": "^3.9.0",
    "gulp-concat": "^2.6.0",
    "gulp-less": "^3.0.3",
    "gulp-minify-css": "^1.2.0",
    "gulp-plumber": "^1.0.1",
    "gulp-rename": "^1.2.2",
    "gulp-uglify": "^1.2.0",
    "karma": "^0.12.0",
    "karma-chai": "^0.1.0",
    "karma-mocha": "^0.2.0",
    "karma-phantomjs-launcher": "^0.2.0",
    "mocha": "^2.2.5"
  }
}

To install this locally I would run npm install and to install all dependencies globally I would run npm install -g . I only want to install gulp globally, though. Is there any way to accomplish this?

As a caveat, I've integrated a gulpfile into a .NET project and have it running via a post-build event. As a pre-build event, I'm executing npm install to ensure everything is setup correctly. My hope is that any code to install only gulp globally can be added to the package.json file so I can keep my pre-build event to just npm install . Unless adding npm install gulp -g to my pre-build event is acceptable...

So @FaridNouriNeshat pointed me to a solution where gulp is accessed locally which is probably the most appropriate thing to do rather than globally install it into someone's machine. In my case, I altered my post-build event in my .NET app to point to the local install of gulp rather than a global install.

"$(SolutionDir)\Gorman.Abe.Web\node_modules\.bin\gulp" styles scripts

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM