Gulp Useref Remove Files From Pipeline

- 1 answer

Is there a way to not output the gulp.src file? My goal is to bundle javascript only and output .js only, not html.

In base.html the following blocks are used to bundle Javascript with gulp-useref:

<!-- build:js app.core.js -->
<script src="{{ STATIC_URL }}etherflex/js/vendor/conditionizr_4.5.1.js"></script>
<script src="{{ STATIC_URL }}etherflex/js/app/conditionizr.detects.js"></script>
<script src="{{ STATIC_URL }}etherflex/js/app/conditionizr.config.js"></script>
<script src="{{ STATIC_URL }}etherflex/js/vendor/mootools-core_1.4.5.js"></script>
<!-- endbuild -->

The gulp task

var gulp = require('gulp');
var notify = require('gulp-notify');
var changed = require('gulp-changed');
var plumber = require('gulp-plumber');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var gzip = require('gulp-gzip');
var useref = require('gulp-useref');
var gulpif = require('gulp-if');

module.exports = function (path) {
    return gulp.src('templates/**/*.html')
        .pipe(plumber({errorHandler: notify.onError("Error: <%= error.message %>")}))
            searchPath: path.source,
            transformPath: function(filePath) {
                return filePath.replace('{{ STATIC_URL }}/','')
        .pipe(changed( + 'js'))
        .pipe(gulpif('*.js', uglify()))
            suffix: ".min",
        .pipe(gulp.dest( + 'js'))
        .pipe(notify("Javascript concatenated, minified and gzip compressed: <%= file.relative %>"))
        .pipe(gulp.dest( + 'js'));

The goal is simply to read the block comments in base.html only and output the bundled javascript app.core.js.

Any suggestions?



To expand on my comment, you can simply use gulp-if to filter the stream for gulp.dest.

.pipe(gulpif('*.js', gulp.dest( + 'js')))