Javascript 如何在终端中运行 gulp 任务
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44955995/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to run gulp tasks in terminal
提问by ark
I am a beginner in gulp. I have created a task named task1 in gulp.js and when i tried to execute that task using "gulp task1" in command line, Its opening the gulp.js file on brackets editor rather than executing in command line. Can somebody help me in solving this problem
我是 gulp 的初学者。我在 gulp.js 中创建了一个名为 task1 的任务,当我尝试在命令行中使用“gulp task1”执行该任务时,它在括号编辑器上打开 gulp.js 文件,而不是在命令行中执行。有人可以帮我解决这个问题吗
The code in my gulp file is
我的 gulp 文件中的代码是
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var jscs = require('gulp-jscs');
gulp.task('task1', function () {
return gulp
.src(['./src/**/x.js', './*.js'])
.pipe(jscs())
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish', {
verbose: true
}));
})
采纳答案by VIX
Have you install Gulp on NPM?. If not, do the following.
你在 NPM 上安装了 Gulp 吗?如果没有,请执行以下操作。
$ npm install gulp
$ npm install jshint gulp-jshint --save-dev
$ npm install --save-dev gulp-jscs
In case it's not installed, try to:
如果未安装,请尝试:
$ sudo npm install -g gulp
$ sudo npm install -g jshint gulp-jshint --save-dev
$ sudo npm install -g --save-dev gulp-jscs
After completing the installation, try gulpon terminal (Remember that you must be in the same directory of the file).
安装完成后,gulp在终端上试试(记住一定要在同一个目录下的文件)。
回答by yBrodsky
In addition to making sure you have gulp globallyinstalled, make sure your gulp file is named *gulpfile.js*and that is in the same directory as where you are running gulp. Then simply run gulp task1. If you run gulpwithout anything else, the default task will run (you can write a task named "default" which will be run in this case.
除了确保全局安装了gulp 之外,还要确保您的 gulp 文件已命名*gulpfile.js*并且与运行gulp. 然后简单地运行gulp task1。如果你gulp没有其他任何东西运行,默认任务将运行(你可以编写一个名为“default”的任务,它将在这种情况下运行。
回答by nagoor
Install gulp globally and run the gulp command from the folder the 'gulpfile.js' is located
全局安装 gulp 并从“gulpfile.js”所在的文件夹运行 gulp 命令
npm install gulp-cli -g npm install gulp -D
npm install gulp-cli -g npm install gulp -D

