我正试图通过一个目录进行美化,并在Assemble创建文件后将html文件美化到同一目录中。一起运行默认任务时,美化会抛出错误:
Running "prettify:indent" (prettify) task
Warning: Object 2 has no method 'indexOf' Use --force to continue
随后,当我单独运行每个任务时,一切正常:
$ grunt assemble; grunt prettify
这是我的Gruntfile:
site: grunt.file.readYAML('src/template/data/site.yml'),
assemble: {
options: {
prettify: {indent: 2},
marked: {sanitize: false},
data: "src/template/data/site.yml",
layoutdir: 'src/template/layouts',
},
all: {
options: {production: false,layout: 'default.hbs'},
files: [
{ expand: true, cwd: 'src/template/pages', src: ['**/*.hbs'], dest: 'dist/' }
]
}
},
prettify: {
options: {
indent: 4,
wrap_line_length: 78,
brace_style: 'expand',
},
all: {
expand: true,
cwd: 'dist/',
ext: '.html',
src: ['*.html'],
dest: 'dist/'
}
}
有人能指出我正确的方向吗?可以将输出美化到同一个源目录吗?
答案 0 :(得分:2)
从汇编选项中删除 prettify: {indent: 2}
。
assemble: {
options: {
marked: {sanitize: false},
data: "src/template/data/site.yml",
layoutdir: 'src/template/layouts',
},
all: {
options: {production: false,layout: 'default.hbs'},
files: [
{ expand: true, cwd: 'src/template/pages', src: ['**/*.hbs'], dest: 'dist/' }
]
}
},
您已在prettify
任务
prettify: {
options: {
indent: 4,
wrap_line_length: 78,
brace_style: 'expand',
},
// Specify a number to padcomments
all: {
files: [
{expand: true, cwd: 'dist/', src: ['*.html'], dest: 'dist/', ext: '.html'}
]
}
},
在汇编选项中指定prettify: {indent: 2}
表示Grunt将使用Gruntfile中不存在的选项prettify:indent
和src: 2
来查找任务dest: indent
。