简体   繁体   中英

Gulp write to js output

Im having trouble writing to js files. Css works wonders, but I cant seem to know why js does not work? Nothing gets written to the output folder.

What have I done wrong? wwwroot and assets are both in projectroot. As mentioned earlier, the CSS writes to file perfectly, and I think it should work like this?

var files = {
    cssInput: 'assets/css/',
    cssOutput: 'wwwroot/css/',
    jsLibsInput: 'assets/js/libs/',
    jsCustomInput: 'assets/js/custom/',
    jsOutput: 'wwwroot/js/'
};

gulp.task('default', ['sass', 'css:min', 'js:min']);
gulp.task('clean', ['css:clean', 'js:clean']);

gulp.task('sass:watch', function () {
    gulp.watch('./sass/**/*.scss', ['sass']);
});

gulp.task('watch', ['default'], function () {
    gulp.watch(files.cssInput + '*.css', ['css']);
    gulp.watch(files.jsLibsInput + '*.js', ['js']);
    gulp.watch(files.jsCustomInput + '*.js', ['js']);
});

// CSS
gulp.task('sass', function () {
    return gulp.src([files.cssInput + '*.scss'])
        .pipe(sass().on('error', sass.logError))
        .pipe(gulp.dest(files.cssInput));
});

gulp.task('css:min', function () {
    gulp.src(files.cssInput + 'abovethefold.css')
        .pipe(csso())
        .pipe(gulp.dest(files.cssOutput));

    return gulp.src([files.cssInput + '*.css', '!' + files.cssInput + 'abovethefold.css'])
        .pipe(concat('all.css'))
        .pipe(csso())
        .pipe(gulp.dest(files.cssOutput));
});

gulp.task('css:clean', function () {
    return del(files.cssOutput);
});

// JavaScript
gulp.task('js:min', function () {
    return gulp.src([
        files.jsLibsInput + '*.js',
        '!' + files.jsLibsInput + '*.min.js',
        files.jsCustomInput + '*.js',
        '!' + files.jsCustomInput + '*.min.js'
    ])
        .pipe(concat('all.js'))
        .pipe(uglify())
        .pipe(gulp.dest(files.jsOutput));
});

gulp.task('js:clean', function () {
    return del(files.jsOutput);
});

So, after getting help from @MikaS I realized there was something wrong in my JS, in this case es6 syntax..

.on('error', (err) => { gutil.log(gutil.colors.red('[Error]'), 
err.toString()); })

That helped me find the error in case anyone else ends up here with similar errors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM