質問

Why am I getting this error if my code is definitely right? Grunt is prompting error:

c:\xampp\htdocs\yeoman\ci-test\Grunt < % if(includeLess) { % > ^ Loading "Gruntfile.js" tasks...ERROR >> SyntaxError: Unexpected token < on build

Code:

grunt.registerTask('serve', [
    <% if(includeLess) { %>
    'less',<% } %>
    'express',
    'open',
    'imagemin',
    'watch'
]);
役に立ちましたか?

解決

<% and %> are opening and closing statements for lodash templates: http://lodash.com/docs#template which Grunt uses within the config.

The templates are just strings, meaning they must be wrapped in ' or " and processed with grunt.template.process: http://gruntjs.com/api/grunt.template#grunt.template.process or when included within the Grunt config, they're process automatically.

But since Gruntfiles are javascript, you don't need to leverage lodash templates in that portion of the Gruntfile. Just use javascript:

var tasks = ['express', 'open', 'imagemin', 'watch'];
if (includeLess) tasks.unshift('less'); // add less to the beginning of array
grunt.registerTask('serve', tasks);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top