本地安装的 gulp 不在命令行中运行? [英] Locally installed gulp not running in command line?

查看:27
本文介绍了本地安装的 gulp 不在命令行中运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 nodejs 和 gulp 的新手.我在一个 nodejs 项目上工作,我必须在所有文件上运行 jslint.为此,我正在使用 gulp.

I am new to nodejs and gulp stuff. I working on a nodejs project in which I have to run jslint on all the files. I am using gulp for this purpose.

我的问题是,为了在 cli 上运行 gulp,我不想全局安装 gulp,也不想更新我的路径变量,所以我已经使用包在本地项目中安装了 gulp 和其他节点模块.json 文件

My problem is that In order to run gulp on cli I don't want to install gulp globally and also does not want to update my path variable, So I have installed gulp and other node modules in my project locally using the package.json file

cd 我的项目

npm 安装

由于我不想全局安装 gulp 并且想运行本地 gulp,因此我在我的 package.json 文件中添加了脚本,如下所示 这个问题

Since I don't want to install gulp globally and want to run the local gulp I have added script in my package.json file like this as given in this question

{
  "name": "",
  "version": "1.0.0",
  "main": "index.js",
  "private": true,
  "dependencies": {
    "async": "1.5.0"
  },
  "devDependencies": {
    "gulp": "^3.9.0",
    "gulp-jslint": "^0.2.2"
  },
  "scripts": {
      "gulp": "./node_modules/.bin/gulp"   // is this correct?
    }
}

在我的 myproject 文件夹中添加了一个 gulpfile.js

Add added a gulpfile.js inside my myproject folder

var gulp = require('gulp'); 

// include plug-ins
var jslint = require('gulp-jslint');

// JS hint task
gulp.task('lint', function() {
  gulp.src('./common/srp/*.js')
    .pipe(jslint())
    .pipe(jslint.reporter('default'));
});

gulp.task("default", ["lint"]);

但是现在在 myproject 文件夹中的命令行上,当我运行 gulp 和 gulp lint 时出现错误

But now on my command line inside myproject folder, when I run gulp and gulp lint I get an error

user1-VirtualBox:~/myproject$ gulp lint

user1-VirtualBox:~/myproject$ gulp lint

/usr/local/node-v0.10.26-linux-x64/bin/gulp 没有这样的文件或目录

/usr/local/node-v0.10.26-linux-x64/bin/gulp No such file or directory

它在全局节点模块中寻找 gulp.

Its looking for gulp in the global node module.

有没有办法让 gulp 在 cli 上运行而无需全局安装和更新 PATH 变量.

Is there a way to make gulp run on cli without installing globally and updating PATH variable.

任何帮助将不胜感激谢谢

Any help will be appreciated Thanks

推荐答案

你可以在node_modules/.bin中找到npm安装的任何可执行文件.因此,您可以使用以下命令在本地运行 gulp:

You can find any executable installed by npm in node_modules/.bin. So you can run gulp locally using:

./node_modules/.bin/gulp

您可以在 no command 'gulp' found - after installation

这篇关于本地安装的 gulp 不在命令行中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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