gulp+browserfy转换配置

gulp + browserify transform configuration

本文关键字:配置 转换 gulp+browserfy      更新时间:2023-11-22

我在browserfy中使用gulp,如何配置brfs-htmlmin?在npm页面上,我发现我应该传递options.minimy对象,但我如何使用browserfy做到这一点?

这不管用,有什么提示吗?(是的,我是新来的,我昨天安装了node/npm;)

gulp.task('scripts', ['clean'], function () {
    gulp.src('Components/initialize.js')
        .pipe(browserify({
            transform: ['brfs-htmlmin', { "opts": {minify: {removeComments: false}} }]
        }))
        .pipe(gulp.dest('./buildjs'));
});

最后我修改了brfs-htmlmin源,但必须有更好的方法

brfs-htmlmin来源:

module.exports = function(file, opts) {
    if(/'.json$/.test(file)) return through();
    opts = opts || {};
    opts.minify = opts.minify || {
        removeComments: false,
        collapseWhitespace: true,
        collapseBooleanAttributes: true,
        removeAttributeQuotes: true,
        removeRedundantAttributes: true,
        removeEmptyAttributes: true
    }; 

虽然没有把配置放在gulpFile.js上那么方便,但你可以把配置放到package.json上。

"//": "browserify transform config doesn't work if placed on gulpFile.js or karma.conf.js",
"browserify": {
    "debug": "true",
    "transform": ["brfs-htmlmin", { "opts": { "minify": {"removeComments": "false" }}}]
}