简体   繁体   English

gulp useref从管道中删除文件

[英]gulp useref remove files from pipeline

Is there a way to not output the gulp.src file? 有没有不输出gulp.src文件的方法? My goal is to bundle javascript only and output .js only, not html. 我的目标是仅捆绑javascript,仅输出.js,而不捆绑html。

In base.html the following blocks are used to bundle Javascript with gulp-useref: base.html ,以下块用于将Javascript与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 gulp任务

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 %>")}))
        .pipe(useref({
            searchPath: path.source,
            transformPath: function(filePath) {
                return filePath.replace('{{ STATIC_URL }}/','')
            }
        }))
        .pipe(changed(path.build + 'js'))
        .pipe(gulpif('*.js', uglify()))
        .pipe(rename({
            suffix: ".min",
        }))
        .pipe(gulp.dest(path.build + 'js'))
        .pipe(notify("Javascript concatenated, minified and gzip compressed: <%= file.relative %>"))
        .pipe(gzip())
        .pipe(gulp.dest(path.build + 'js'));
};

The goal is simply to read the block comments in base.html only and output the bundled javascript app.core.js . 我们的目标只是简单地读取base.html中的块注释并输出捆绑的javascript app.core.js

Any suggestions? 有什么建议么?

要扩展我的评论,您可以简单地使用gulp.dest gulp-if过滤gulp.dest的流。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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