我正在使用 grunt-contrib-htmlmin
插件。这就是我的 Gruntfile.js
的样子:
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']);
};
没什么特别的,真的。我的 404.html 也很简单,但即使在更简单的 HTML
文件上,grunt 也不起作用。例如,假设采用以下 HTML
文件:
<html>
<head>
</head>
<body>
</body>
</html>
它甚至对那个不起作用。我在控制台中得到的结果是:
Running "htmlmin:dist" (htmlmin) task
Minified 0 files (1 failed)
Done, without errors.
我在哪里可以看到失败的原因?
我尝试了很多东西,比如删除 options
,我还尝试更改 file
结构,结果是这样的:
files: {
expand: true,
cwd: 'views/src/',
src: '404.html',
build: 'views/build/404.html'
}
但这也不起作用,我现在得到的错误是:
Running "htmlmin:dist" (htmlmin) task
Warning: pattern.indexOf is not a function Use --force to continue.
Aborted due to warnings.
我做错了什么?
最佳答案
我不知道错误的真正原因。但是通过添加方括号修改源代码,如下所示,对我有用。
files: [{
expand: true,
cwd: 'views/src/',
src: '404.html',
build: 'views/build/404.html'
}]
关于javascript - 咕噜 htmlmin 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33057209/