문제

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