在gulp-inline中运行gulp-clean-css选项

时间:2016-06-07 16:29:42

标签: gulp gulp-clean-css

如何在gulp中配置嵌套插件的选项? 我有一个gulp任务,使用gulp-inline来内联任何css和js。

gulp-inline具有设置css处理器的选项

gulp.task('html', function () {

  gulp.src(source + '**/*.+(html|php)')
    .pipe($.plumber())
    .pipe($.inline({
        base: source,
        js: $.uglify,
        css: $.cleanCss,
        disabledTypes: ['svg', 'img']
    }))
    .pipe(gulp.dest(build))
});

理想情况下,在运行任务时,我想为css和js

声明配置选项
gulp.task('html', function () {

  gulp.src(source + '**/*.+(html|php)')
    .pipe($.plumber())
    .pipe($.inline({
        base: source,
        js: $.uglify,
        css: $.cleanCss({
            keepBreaks: false,
            advanced: false,
            keepSpecialComments: '*',
            aggressiveMerging: false
        }),
        disabledTypes: ['svg', 'img']
    }))
    .pipe(gulp.dest(build))
});

1 个答案:

答案 0 :(得分:1)

只需传递一个返回cleanCss变换的函数:

gulp.task('html', function () {
  gulp.src(source + '**/*.+(html|php)')
    .pipe($.plumber())
    .pipe($.inline({
        base: source,
        js: $.uglify,
        css: function() {
          return $.cleanCss({ /* options */ });
        },
        disabledTypes: ['svg', 'img']
    }))
    .pipe(gulp.dest(build))
});