1

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?

HGB
  • 2,157
  • 8
  • 43
  • 74

1 Answers1

3

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

var $ = require('gulp-load-plugins')({lazy: true});
Ufuk Hacıoğulları
  • 37,978
  • 12
  • 114
  • 156