1

I found an HTML compression gulp plugin that I want to use. I encountered a coding problem.

This is written in someone else's plugin:

gulp.task ('indexHtml', function () {
    return gulp.src ('index.html')
        .pipe (cheerio (function ($) {
            $ ('script'). remove ();
            $ ('link'). remove ();
            $ ('body'). append ('<script src = "skin / zhuce / MergeMin / app.full.min.js"> </ script>');
            $ ('head'). append ('<link rel = "stylesheet" href = "skin / zhuce / MergeMin / app.full.min.css">');
        })))
        .pipe (gulp.dest ('test /'));
});

But the output is unified Unicode. Cause some characters cannot be read only in the browser to explain.

I searched and found a solution that others pointed out:

Use cheerio.load (html, {decodeEntities: false});

Incoming parameters

But I do not know how to do it in Node.js.

I'm facing this nesting in the above code:

.pipe (cheerio (function ($) {

I do not know how to change: cheerio.load (html, {decodeEntities: false});.

Mika Sundland
  • 18,120
  • 16
  • 38
  • 50
武一鸣
  • 13
  • 3
  • My answer is based off of the gulp-cheerio nom website located at https://www.npmjs.com/package/gulp-cheerio if you want to do more reading. – SteveB Jan 28 '18 at 15:39

1 Answers1

0

Assuming you are using gulp-cheerio, you need to change:

.pipe (cheerio (function ($) {
        $ ('script'). remove ();
        $ ('link'). remove ();
        $ ('body'). append ('<script src = "skin / zhuce / MergeMin / app.full.min.js"> </ script>');
        $ ('head'). append ('<link rel = "stylesheet" href = "skin / zhuce / MergeMin / app.full.min.css">');
    })))

To:

.pipe (cheerio ({
    run: (function ($) {
        $ ('script'). remove ();
        $ ('link'). remove ();
        $ ('body'). append ('<script src = "skin / zhuce / MergeMin / app.full.min.js"> </ script>');
        $ ('head'). append ('<link rel = "stylesheet" href = "skin / zhuce / MergeMin / app.full.min.css">');
    }))),
    parserOptions: {
    decodeEntities: false,
    //other options here
  }
})
SteveB
  • 894
  • 7
  • 15