我正在使用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.我做错了什么?
发布于 2015-11-18 09:00:00
我不知道错误的真正原因。但是,通过添加正方形的brackes来修改源代码,如下所示,对我很有帮助。
files: [{
expand: true,
cwd: 'views/src/',
src: '404.html',
build: 'views/build/404.html'
}]发布于 2016-11-28 15:24:01
请注意,在“文件”中,您应该先指定目标路径,然后再指定SRC路径。
htmlmin: {
dist: {
options: {
/* options here*/
},
files: {
'path/to/destination/folder/404.html': 'path/to/src/folder/404.html'
}
}
}https://stackoverflow.com/questions/33057209
复制相似问题