Eduardo Poço
Eduardo Poço

Reputation: 3089

html-minifier: process inline scripts witout type

I am using html-minifier inside gulp to minify my html files. However, inline script tags without type="text/javascript" never get processed.

I've been searching in the documentation, but even the option processScripts, with minifyJS, was not able to solve it.

My script tags have no type, as it is not necessary in HTML5 (or am I wrong about this one?). What am I missing?

script.js:

const gulp = require('gulp');
const htmlmin = require('gulp-htmlmin');

gulp.src('lib/*.html')
    .pipe(htmlmin({
        collapseWhitespace: true,
        removeComments: true,
        minifyCSS: true,
        minifyJS: true,
        removeScriptTypeAttributes: true,
        processScripts: [undefined, null, ""],
    }))
    // .pipe(htmlmin({
        // collapseWhitespace: true,
        // minifyJS: true,
    // }))
    .pipe(gulp.dest('dist'));

EDIT

Running html-minifier directly in the string correctly minifies it. So, some sort of bug seems to be preventing options passed to gulp from arriving to html-minifier used internally.

Upvotes: 0

Views: 439

Answers (1)

Aaron McGuire
Aaron McGuire

Reputation: 1255

I ran the following gulp project on an example html page that had inline scripts and html, with the parameter set to minifyJS:true it all worked. You are definitely looking at the correct parameter. Could it be that the way you are passing in your configuration parameters is not being recognised? Hopefully the example gulpfile code will help you somewhat.

const gulp = require('gulp');
const htmlmin = require('gulp-htmlmin');
 
function defaultTask() {
        return gulp.src('src/*.html')
          .pipe(htmlmin({ 
              collapseWhitespace: true,
              minifyJS:true }))
          .pipe(gulp.dest('dist'));
  }
  
  exports.default = defaultTask;

Upvotes: 0

Related Questions