GULP:gulp没有定义 [英] GULP: gulp is not defined
问题描述
如下面的屏幕截图所示,我无法运行 gulp
来连接JavaScript文件。它的意思是 gulp没有被定义
。
我试过以下命令:
npm install -g gulp
npm install gulp
npm install gulp --save-dev
我还设置了以下环境变量:
C:\Users\<使用者> \AppData\Roaming\\\
pm; C:\Python27; C:\Users\<使用者> \AppData\Roaming\ npm\\\
ode_modules; C:\Users\<使用者> \AppData\Roaming\\\
pm\\\
ode_modules\gulp;
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
//脚本路径
var jsFiles ='scripts / *。js',
jsDest ='dist / scripts';
$ b $ gulp.task('scripts',function(){
return gulp.src(jsFiles)
.pipe(concat('scripts.js'))
.pipe(gulp.dest(jsDest));
});
您只需要安装并需要 gulp
local ,您可能只在全局安装它
在命令行
cd< project-root> &安培;&安培; npm install --save-dev gulp
在您的gulpfile.js中
var gulp = require('gulp');
这是与命令行依赖关系(全局安装)不同的依赖关系。更具体地说,它是相同的NPM软件包,但命令行程序通常会从NPM软件包中不同的入口点执行代码,然后返回需要('X')。
如果我们转到Github的Gulp项目中的package.json文件,它会告诉我们整个故事:
{
name:gulp,
description:流式生成系统,
version:3.9.1,
homepage :http://gulpjs.com,
repository:gulpjs / gulp,
author:分形< contact@wearefractal.com>(http:// wearefractal。
build,
build,
stream,
system,
make,
工具,
资产,
管道
],
文件:[
index.js,
lib ,
bin,
完成,
gulp.1
,
bin:{
gulp: ./bin/gulp.js
},
man:gulp.1,
dependencies:{
// ...
},
devDependencies:{
// ...
},
脚本:{
prepublish:marked-man --name gulp docs / CLI.md> gulp.1,
lint:eslint。 &安培;&安培; jscs * .js bin / lib / test /,
pretest:npm run lint,
test:mocha --reporter spec,
coveralls: 伊斯坦布尔封面_mocha - 报告lcovonly - -R spec&&猫./coverage/lcov.info |工作服&& rm -rf ./coverage
},
engines:{
node:> = 0.9
},
license: MIT
}
所以在命令行中:
$ gulp默认
会执行此操作:
bin:{
gulp:./bin/gulp.js
},
另一方面,您的代码中的require('gulp')将会返回这个值:
https://github.com/gulpjs/gulp/blob/master/index.js
通常我们会在package.json文件中看到这一点:
main:index.js
但是因为这是默认设置,所以他们只是省略了它(这是笨拙的IMO,最好是明确的,但它们不是我见过的第一个使用蹩脚速记路线的项目。)。
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
.
I have tried the following commands:
npm install -g gulp
npm install gulp
npm install gulp --save-dev
I have also set the environment variables as following:
C:\Users\<user>\AppData\Roaming\npm;C:\Python27;C:\Users\<user>\AppData\Roaming\npm\node_modules;C:\Users\<user>\AppData\Roaming\npm\node_modules\gulp;
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));
});
you just need to install and require gulp
locally, you probably only installed it globally
At the command line
cd <project-root> && npm install --save-dev gulp
In your gulpfile.js
var gulp = require('gulp');
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.
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": [
"build",
"stream",
"system",
"make",
"tool",
"asset",
"pipeline"
],
"files": [
"index.js",
"lib",
"bin",
"completion",
"gulp.1"
],
"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",
"test": "mocha --reporter spec",
"coveralls": "istanbul cover _mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage"
},
"engines": {
"node": ">= 0.9"
},
"license": "MIT"
}
so at the command line:
$ gulp default
will execute this:
"bin": {
"gulp": "./bin/gulp.js"
},
on the other hand, require('gulp') in your code will return the value of this:
https://github.com/gulpjs/gulp/blob/master/index.js
normally we see this in a package.json file as:
"main": "index.js"
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.).
这篇关于GULP:gulp没有定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!