javascriptnpmgulp

Why is npm library not a function?


There is a problem with npm library for html minify. I downloaded and declared a library

import htmlmin from 'html-minifier'; 

but when i try to run a gulp task

export const html = () => {
  return gulp.src("source/*.html")
    .pipe(htmlmin({ collapseWhitespace: true }))
    .pipe(gulp.dest("build"));
}

but a got an error

TypeError: htmlmin is not a function

I am pretty sure there is no syntax error but I dont know what is a problem.

I tried different liabraries and more old node.js but I still got same problem


Solution

  • it worked after I instaled special library for gulp gulp-htmlmin after a have seen usage for this one

    const gulp = require('gulp');
    const htmlmin = require('gulp-htmlmin');
    
    gulp.task('minify', () => {
      return gulp.src('src/*.html')
        .pipe(htmlmin({ collapseWhitespace: true }))
        .pipe(gulp.dest('dist'));
    });