Search code examples
javascriptgulpgulp-4

Migrating to Gulp 4, [not creating scripts and Running the server. No Error Shown]


I migrated from gulp 3.9.1 to 4.0.2, I resolved the issues where needed to introduce gulp.series and gulp.parallel.

In the app folder i generate i dont see my scripts being generated apart from css files.

gulpfile.js

var gulp        = require('gulp');
var templates   = require('./tools/gulp-templates.js');
var scripts     = require('./tools/gulp-scripts.js');
var styles      = require('./tools/gulp-styles.js');
var fonts       = require('./tools/gulp-fonts.js');
var build       = require('./tools/gulp-build.js');
var run         = require('./tools/gulp-run.js');

gulp.task('default', );

gulp.task('templates', templates);

gulp.task('scripts',gulp.parallel('templates'), scripts);

gulp.task('styles', styles);

gulp.task('fonts', fonts);

gulp.task('build', gulp.parallel('styles', 'scripts','fonts'), build);

gulp.task('run', gulp.parallel('build'), run);

gulp-scripts.js

let headerComment = require('gulp-header-comment');
let git = require('git-rev');
let strip = require('gulp-strip-comments');

let b = browserify({
    detectGlobals: false,
    entries: './src/app.js',
    debug: true
}).transform("babelify", {
    presets: [['es2015', {loose: true}], 'stage-0'],
    plugins: ['transform-proto-to-assign']
});

module.exports = function() {

        git.long(function (str) {

            return b.bundle()
                .pipe(source('app.js'))
                .pipe(buffer())
                .pipe(strip())
                .pipe(streamify(uglify({compress: true, beautify: false})))
                .pipe(headerComment(`Generated on <%= moment().format() %>
                    Commit: ${str}  
                `))
                .pipe(gulp.dest('./app/'))
        })
};

App folder before migration

enter image description here

App folder after migration

enter image description here

Console Output with ought errors

enter image description here


Solution

  • First thing I would change is some of your tasks like

    gulp.task('scripts',gulp.parallel('templates'), scripts);

    gulp.task('build', gulp.parallel('styles', 'scripts','fonts'), build);

    gulp.task('run', gulp.parallel('build'), run);

    Here is the task signature from the docs (https://gulpjs.com/docs/en/api/task#signature)

    task([taskName], taskFunction)

    You have gulp.task('run', gulp.parallel('build'), run); that last run has to be part of the argument taskFunction so you probably want :

    gulp.task('run', gulp.series('build', run));

    gulp.task('build', gulp.series( gulp.parallel('styles', 'scripts','fonts'), build)); and

    gulp.task('scripts',gulp.series('templates', scripts));

    You may have other issues but start with the above changes.