Tommz Tommz - 9 days ago 5
Javascript Question

Grunt htmlmin errors

I'm using

grunt-contrib-htmlmin
plugin. This is how my
Gruntfile.js
looks like:

module.exports = function(grunt) {

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),

htmlmin: {
dist: {
options: {
removeComments: true,
collapseWhitespace: true
},
files: {
'/views/build/404.html': '/view/src/404.html'
}
}
}
});

grunt.loadNpmTasks('grunt-contrib-htmlmin');

grunt.registerTask('default', ['htmlmin']);
};


Nothing special, really. My 404.html is also pretty simple, but even on simpler
HTML
files, grunt doesn't work. For example, let's say take following
HTML
file:

<html>
<head>
</head>
<body>
</body>
</html>


It doesn't even work on that. What I get as a result in console is:

Running "htmlmin:dist" (htmlmin) task
Minified 0 files (1 failed)

Done, without errors.


Where can I see why it failed?

I tried really many things like removing
options
and I also tried changing
file
structure where I ended up with this:

files: {
expand: true,
cwd: 'views/src/',
src: '404.html',
build: 'views/build/404.html'
}


But that doesn't work either and error that I'm getting now is this:

Running "htmlmin:dist" (htmlmin) task
Warning: pattern.indexOf is not a function Use --force to continue.

Aborted due to warnings.


What am I doing wrong?

Answer

I don't know the actual reason for the error. But modifying the source by adding square brackes, as below, worked for me.

files: [{
    expand: true,
    cwd: 'views/src/',
    src: '404.html',
    build: 'views/build/404.html'
}]