grunt-ts
grunt-ts copied to clipboard
Grunt attempts to process htmlOutputTemplate option
I'm using [email protected] and when I specify a custom htmlOutputTemplate, I get this fairly cryptic error:
Running "ts:custom-template" (ts) task
Warning: An error occurred while processing a template (content is not defined). Use --force to continue.
Aborted due to warnings.
I've created a minimal configuration that reproduces the problem.
The issue appears to be the config.get function, which is documented to automatically process Lo-dash templates:
Template strings can be processed manually using the provided template functions. In addition, the
config.getmethod (used by many tasks) automatically expands<% %>style template strings specified as config data inside theGruntfile.
I'm not familiar enough with Grunt to know what the fix is. Hopefully it's as simple as just reading off the configuration object without calling get on it. If not, would you be amenable to allowing a function instead? It could have the same signature as the Lo-dash template, that is, (variables: { content: string, modulename: string, varname: string}) => string.
Thanks for reporting. Works with old Grunt but seems broken with 1.0.1. Will investigate further. I don't know if it's possible for you, but if you go back to Grunt 0.4.5 it should work.
This may be a breaking change in 1.x Grunt - I'm going to ask the folks at the Grunt repo. You identified the correct issue. The good news is that it's workaroundable by escaping the < and > chars with double backslashes.
https://lodash.com/docs#template
test_issue357: {
test: true,
html: ['test/test357/file.html'],
src: ['./test/test357/'],
options: {
compile: false,
htmlOutputTemplate: 'export default \'\\<%= content %\\>\''
}
}
@gustavderdrache Thanks for the report - I think that the fix will be simply escaping the < and > chars in your templates as specified above if you're using Grunt >= 1.0. I will document this with the next patch.
Sounds good. Thanks for the follow-up!
The above workaround does not seem to work for me.
output in the *.html.ts:
export default '\<%= content %\>'
grunt:
$ grunt --version
grunt-cli v1.2.0
grunt v1.0.1
grunt-ts:
$ npm ls | grep grunt-ts
├─┬ [email protected]
├─┬ [email protected]
-Updated PS: could this be useful in finiding a fix: https://github.com/gruntjs/grunt/issues/123
Any news or workaround?
Sorry I have not been able to identify a solution.