$是没有定义的脚本Gulp任务

嗨,我正在尝试运行我的脚本任务吞咽。 我的脚本path定义如下:

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

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

我的g task任务如下:

 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

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

 [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 

再次,另一个模糊的错误“未定义不是一个函数”,这是明确的? 有没有$function缺失?

您可能需要使用gulp-load-plugins软件包:

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