mlegenhausen/grunt-ng-constant

Template error usign grunt.config()

epplestun opened this issue · 2 comments

I'm using grunt-ng-constant 0.4.7 with grunt 0.4.1, when I run ngconstant task I get this error:

A special character was detected in this template. Inside template tags, the
\n and \r special characters must be escaped as \n and \r. (grunt 0.4.0+)
Warning: An error occurred while processing a template (Unexpected token ILLEGAL). Use --force to continue.

I found the problem in this lines:

result = grunt.template.process(wrap, { delimiters: "square", data: _.extend(grunt.config(), { '__ngModule': result }) }); If I use grunt.config() don't works well, but if I don't extend grunt.config() all works fine ... Why extend?

If is not necesary, is posible to remove?

Thanks!

Can you give me your complete configuration including your wrap template? It does not seem that the problem lies in ng-constant it seems your wrap template has some invalid characters.

The lines you have postet allows you to reference config variables in your wrap template. But I think it is cleaner not to extend the original config. You can try to modify the extend call to _.extend({}, grunt.config(), { ... }). This will create a swallow copy of the grunt config. This should prevent side effects in other tasks.

Hi, here is my template:

ngconstant: { dev: [{ dest: 'src/main/modules/config.js', name: 'config', wrap: 'define(["angular"], function (angular) {\n"use strict";\nreturn <%= __ngModule %>});', constants: { 'config': grunt.file.readJSON('config/dev.json') } }], pro: [{ dest: 'src/main/modules/config.js', name: 'config', wrap: 'define(["angular"], function (angular) {\n"use strict";\nreturn <%= __ngModule %>});', constants: { 'config': grunt.file.readJSON('config/pro.json') } }] }