$是未定义的脚本Gulp任务 [英] $ Is not defined scripts Gulp task

查看:201
本文介绍了$是未定义的脚本Gulp任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我正尝试在gulp中运行我的脚本任务。我的脚本路径定义如下:

  scripts:{
coffee:[
'app / assets /scripts/**/*.coffee'
],
js:[
'src / js / *',
'src / js / ** / *'
],
map:['src / js / ** / *。map']
},

我的原始文件路径位于root / src / js /中,我希望将脚本放在root / app / assets / scripts /中的缩小版本中。



我的gulp任务如下:

  gulp.task('scripts',function (){
return gulp.src('app / scripts / ** / *。js')
.pipe($。if('*。js',$ .uglify({preserveComments:' ($。sourcemaps.init())
.pipe($。concat('app.js'))
.pipe($。sourcemaps。 write('./'))
.pipe(gulp.dest('app / assets / scripts'));
});

但由于某种原因,我一直得到这个错误
[13:28:46] ReferenceError:$没有在Gulp中定义
。< anonymous> (C:\ Users \Myuser\apps\myapp\gulpfile.js:165:9)
在module.exports(C:\ Users \Myuser\apps\myapp\
在Gulp.Orchestrator._runTask(C:\ Users \Myuser\apps)
在Gulp.Orchestrator._runTask(C:\ Users \Myuser\apps \myapp\\\
ode_module
s\gulp\\\
ode_modules\orchestrator\index.js:273:3)
在Gulp.Orchestrator._runStep(C:\ Users \Myuser\在Gulp.Orchestrator.start(C:\Users\Myuser\\)上



$ b $ s $($ C $ \ Users \Model \\\\\\\\\\\\\\\\\' \\apps\myapp\\\
ode_modules\g
ulp \\\
ode_modules\orchestrator\index.js:134:8)
在C:\ Users \Myuser\AppData\ Roaming\\\
pm\\\
ode_modules\gulp\bin\gulp.js:129:2
0
at process._tickCallback(node.js:355:11)
at Function .Module.runMa in(module.js:503:11)
在启动时(node.js:129:16)
在node.js:814:3

更新

嘿,我认为你们都是对的。 $ 未定义,应该是 $ = require('gulp-load-plugins')(); 。但是现在我运行 scripts ,出现以下错误:

  [15:24:46] TypeError:undefined不是一个函数
在Gulp。< anonymous> (C:\ Users \Myuser\apps\myapp\gulpfile.js:166:13)
在module.exports(C:\ Users \Myuser\apps\myapp\
在Gulp.Orchestrator._runTask(C:\ Users \Myuser\apps)
在Gulp.Orchestrator._runTask(C:\ Users \Myuser\apps \myapp\\\
ode_module
s\gulp\\\
ode_modules\orchestrator\index.js:273:3)
在Gulp.Orchestrator._runStep(C:\ Users \Myuser\在Gulp.Orchestrator.start(C:\Users\Myuser\\)上



$ b $ s $($ C $ \ Users \Model \\\\\\\\\\\\\\\\\' \\apps\myapp\\\
ode_modules\g
ulp \\\
ode_modules\orchestrator\index.js:134:8)
在C:\ Users \Myuser\AppData\ Roaming\\\
pm\\\
ode_modules\gulp\bin\gulp.js:129:2
0
at process._tickCallback(node.js:355:11)
at Function .Module.runM ain(module.js:503:11)
在启动时(node.js:129:16)
在node.js:814:3

同样,另一个模糊错误未定义不是函数,这是否明确?是否有 $ 函数缺失?

解决方案

您可能需要使用 gulp-load-plug 包裹:

  var $ = require('gulp-load-plugins')({lazy:true}); 


Hi I am trying to run my scripts task in gulp. My scripts path is defined as follows:

scripts: {
        coffee: [
            'app/assets/scripts/**/*.coffee'
        ],
        js: [
            'src/js/*',
            'src/js/**/*'
        ],
        map: ['src/js/**/*.map']
    },

My original file paths are located in root/src/js/ and I want my scripts to be placed in their minified version inside root/app/assets/scripts/.

My gulp task is as follows:

gulp.task('scripts', function() {
    return gulp.src('app/scripts/**/*.js')
        .pipe($.if('*.js', $.uglify({preserveComments: 'some'})))
        .pipe($.sourcemaps.init())
        .pipe($.concat('app.js'))
        .pipe($.sourcemaps.write('./'))
        .pipe(gulp.dest('app/assets/scripts'));
});

But for some reason I keep getting this error
[13:28:46] ReferenceError: $ is not defined
    at Gulp.<anonymous> (C:\Users\Myuser\apps\myapp\gulpfile.js:165:9)
    at module.exports (C:\Users\Myuser\apps\myapp\node_modules\gulp\node_
modules\orchestrator\lib\runTask.js:34:7)
    at Gulp.Orchestrator._runTask (C:\Users\Myuser\apps\myapp\node_module
s\gulp\node_modules\orchestrator\index.js:273:3)
    at Gulp.Orchestrator._runStep (C:\Users\Myuser\apps\myapp\node_module
s\gulp\node_modules\orchestrator\index.js:214:10)
    at Gulp.Orchestrator.start (C:\Users\Myuser\apps\myapp\node_modules\g
ulp\node_modules\orchestrator\index.js:134:8)
    at C:\Users\Myuser\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:129:2
0
    at process._tickCallback (node.js:355:11)
    at Function.Module.runMain (module.js:503:11)
    at startup (node.js:129:16)
    at node.js:814:3

UPDATE

Hey I think you are both right. $ was not defined and should be $ = require('gulp-load-plugins')();. However now that I am running scripts, I get the following error:

[15:24:46] TypeError: undefined is not a function
    at Gulp.<anonymous> (C:\Users\Myuser\apps\myapp\gulpfile.js:166:13)
    at module.exports (C:\Users\Myuser\apps\myapp\node_modules\gulp\node_
modules\orchestrator\lib\runTask.js:34:7)
    at Gulp.Orchestrator._runTask (C:\Users\Myuser\apps\myapp\node_module
s\gulp\node_modules\orchestrator\index.js:273:3)
    at Gulp.Orchestrator._runStep (C:\Users\Myuser\apps\myapp\node_module
s\gulp\node_modules\orchestrator\index.js:214:10)
    at Gulp.Orchestrator.start (C:\Users\Myuser\apps\myapp\node_modules\g
ulp\node_modules\orchestrator\index.js:134:8)
    at C:\Users\Myuser\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:129:2
0
    at process._tickCallback (node.js:355:11)
    at Function.Module.runMain (module.js:503:11)
    at startup (node.js:129:16)
    at node.js:814:3

Again, another vague error "undefined is not a function", is this explicit? Is there a $ function missing?

解决方案

You probably need to use gulp-load-plugins package:

var $ = require('gulp-load-plugins')({lazy: true});

这篇关于$是未定义的脚本Gulp任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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