shkuznetsov / gulp-minify-inline

gulp plugin that minifies inline JS and CSS
MIT License
28 stars 5 forks source link

Inline minification fails with an EJS tag and a <script> tag #21

Closed StructByLightning closed 5 years ago

StructByLightning commented 6 years ago

Using an EJS tag with a script tag that contains code causes gulp-minify-inline to destroy the EJS tag.

It turns: <%- include("/partials/head.ejs") %> into <%- include("="" partials="" head.ejs")="" %="">, which is meaningless gibberish (Express throws an error when it tries to parse it).

The mangling doesn't occur if a file only contains <script> tags or EJS tags. It's only when both are present in the same file that the EJS tags are destroyed.

The only gulp task I'm running is minifyInline, so it's definitely being caused by it. Here is my EJS file (renamed to .txt for github) and my gulpfile.

shkuznetsov commented 5 years ago

Hello there. Apparently, EJS is getting mangled by cheerio, as the following snippet clearly shows:

const source = '<html><head><%- include("/partials/head.ejs") %></head><body></body></html>';
console.log(require('cheerio').load(source, {decodeEntities: false}).html());

>>> <html><head><%- include("="" partials="" head.ejs")="" %=""></%-></head><body></body></html>

That kind of makes sense because cheerio is an HTML parser, and EJS ain't HTML, therefore results may vary.

Also, looks like cheerio has been abandoned by its maintainer, so we're unlikely to get any traction even if we raise an issue there.

With the above I have to close this issue.