Search code examples
javascriptnode.jsgulpbrowserifybrfs

gulp + browserify transform configuration


I'm using gulp with browserify, how can I configure brfs-htmlmin? on npm page i find out I should pass options.minify object but how can I do that using browserify?

This doesn't work, any hints? (yes i'm new I installed node/npm yesterday;)

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

In the end i modified brfs-htmlmin source but there must be better way

brfs-htmlmin source:

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
    }; 

Solution

  • Though not as convenient as putting the configuration on gulpFile.js you can put the configuration on 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" }}}]
    }