1

在 Assemble 创建文件后,我试图让 prettify 运行一个目录并将 html 文件美化到同一目录中。一起运行默认任务时,prettify 会抛出错误:

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/'
  }
}

有人可以指出我正确的方向吗?可以美化输出到相同的源目录吗?

4

1 回答 1

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'}
    ]
  }
},

在 Assemble 中指定prettify: {indent: 2}选项意味着 Grunt 将寻找prettify:indent带有选项的任务,src: 2dest: indent这些选项在您的 Gruntfile 中不存在。

于 2014-01-10T16:53:43.340 回答