简体   繁体   中英

gulp will not output js min file

Cant seem to find my problem here. After I run Gulp, the all-css.min.css gets outputted to _build folder but the JS will not go! am I missing something? Cant seem to find what is making this not work.

var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var minifyHTML = require('gulp-minify-html');
var sourcemaps = require('gulp-sourcemaps');
var minifyCSS = require('gulp-minify-css');
var inlineCss = require('gulp-inline-css');
var rev = require("gulp-rev");
var del = require('del');

var jsBase = {
    src: [
        '/Scripts/Core/ko.bindinghandlers-1.0.0.js',
        '/Scripts/Twitter/typeahead-0.10.2.js',
        '/Scripts/LdCore/mobile-core.js',
        '/Scripts/LDCore/Chat.js',
        '/Scripts/unsure.js' // These have any unknown lines in them. 
    ]
};

gulp.task('clean', function () {
    del.sync(['_build/*'])
});

gulp.task('produce-css', function () {
    return gulp.src(cssBase.src)
    .pipe(minifyCSS({ keepBreaks: false }))
    .pipe(concat('all-css.min.css'))
    .pipe(gulp.dest('_build/'))
});


gulp.task('produce-minified-js', function () {
    return gulp.src(jsBase.src)
      //.pipe(sourcemaps.init())
      //.pipe(uglify())
      .pipe(concat('all.min.js'))
      //.pipe(rev()) // adds random numbers to end.
      //.pipe(sourcemaps.write('.'))
      .pipe(gulp.dest('_build/'));
});


gulp.task('default', ['clean'], function () {
    gulp.start('produce-css', 'produce-minified-js');
});

According to Contra at this post , we shouldn't be using gulp.start.

gulp.start is undocumented on purpose because it can lead to complicated build files and we don't want people using it

Bad:

gulp.task('default', ['clean'], function () {
    gulp.start('produce-css', 'produce-minified-js');
});

Good:

gulp.task('default', ['clean','produce-css','produce-minified-js'], function () {
    // Run the dependency chains asynchronously 1st, then do nothing afterwards.
});

It's totally legit to have nothing in the gulp.task, as what it's doing is running the dependency chains asynchronously & then terminating successfully.

You could also do the following:

gulp.task('default', ['clean','produce-css','produce-minified-js'], function (cb) {
    // Run a callback to watch the gulp CLI output messages. 
    cb();
});

Since Gulp creates "Starting default" on the CLI, this would help to display "Finished default" in the CLI after everything else runs.

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