吞咽:吞咽未定义 [英] GULP: gulp is not defined
问题描述
如下面的屏幕截图所示,我无法运行 gulp
来连接 JavaScript 文件.它说 gulp 没有定义
.
As shown in the screen shot below I am not able to run gulp
to concat the JavaScript files. Its saying that gulp is not defined
.
我尝试了以下命令:
npm install -g gulp
npm install gulp
npm install gulp --save-dev
我还设置了如下环境变量:
I have also set the environment variables as following:
C:Users<user>AppDataRoaming
pm;C:Python27;C:Users<user>AppDataRoaming
pm
ode_modules;C:Users<user>AppDataRoaming
pm
ode_modulesgulp;
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
//script paths
var jsFiles = 'scripts/*.js',
jsDest = 'dist/scripts';
gulp.task('scripts', function() {
return gulp.src(jsFiles)
.pipe(concat('scripts.js'))
.pipe(gulp.dest(jsDest));
});
推荐答案
你只需要安装并且需要 gulp
locally,你可能只需要全局安装
you just need to install and require gulp
locally, you probably only installed it globally
在命令行
cd <project-root> && npm install --save-dev gulp
在你的 gulpfile.js 中
In your gulpfile.js
var gulp = require('gulp');
这是与命令行依赖项(您全局安装的)不同的依赖项.更具体地说,它是同一个 NPM 包,但命令行程序通常会从 NPM 包中的不同入口点执行代码,然后 require('X') 将返回.
this is a different dependency than the command line dependency (that you installed globally). More specifically, it is the same NPM package, but the command line program will execute code usually from a different entry point in the NPM package then what require('X') will return.
如果我们转到 Github 上 Gulp 项目中的 package.json 文件,它会讲述整个故事:
If we go to the package.json file in the Gulp project on Github, it will tell the whole story:
{
"name": "gulp",
"description": "The streaming build system",
"version": "3.9.1",
"homepage": "http://gulpjs.com",
"repository": "gulpjs/gulp",
"author": "Fractal <contact@wearefractal.com> (http://wearefractal.com/)",
"tags": [ ],
"files": [
// ...
],
"bin": {
"gulp": "./bin/gulp.js"
},
"man": "gulp.1",
"dependencies": {
// ...
},
"devDependencies": {
// ...
},
"scripts": {
"prepublish": "marked-man --name gulp docs/CLI.md > gulp.1",
"lint": "eslint . && jscs *.js bin/ lib/ test/",
"pretest": "npm run lint",
},
"engines": {
"node": ">= 0.9"
},
"license": "MIT"
}
所以在命令行:
$ gulp default
会执行这个:
"bin": {
"gulp": "./bin/gulp.js"
},
另一方面,代码中的 require('gulp') 将返回 this 的值:
on the other hand, require('gulp') in your code will return the value of this:
https://github.com/gulpjs/gulp/blob/master/index.js
通常我们会在 package.json 文件中看到:
normally we see this in a package.json file as:
"main": "index.js"
但由于这是默认设置,他们只是省略了它(这是愚蠢的 IMO,最好是明确的,但它们不是我见过的第一个采用蹩脚的速记路线的项目.
but since this is the default, they just omitted it (which is dumb IMO, better to be explicit, but they aren't the first project I have seen take the lame shorthand route.).
这篇关于吞咽:吞咽未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!