Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grunt attempts to process htmlOutputTemplate option #357

Open
gustavderdrache opened this issue May 27, 2016 · 7 comments
Open

Grunt attempts to process htmlOutputTemplate option #357

gustavderdrache opened this issue May 27, 2016 · 7 comments

Comments

@gustavderdrache
Copy link

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.get method (used by many tasks) automatically expands <% %> style template strings specified as config data inside the Gruntfile.

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.

@nycdotnet
Copy link
Contributor

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.

@nycdotnet
Copy link
Contributor

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 %\\>\''
              }
            }

@nycdotnet
Copy link
Contributor

@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.

@gustavderdrache
Copy link
Author

Sounds good. Thanks for the follow-up!

@TannerPO
Copy link

TannerPO commented Jun 22, 2016

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: gruntjs/grunt#123

@viceice
Copy link

viceice commented Dec 17, 2018

Any news or workaround?

@nycdotnet
Copy link
Contributor

Sorry I have not been able to identify a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants