Uglify/minify Polymer web components using gulp

2019-08-12 12:32发布

I am trying to minify my web components using gulp's uglify plugin but it fails because it does not recognize the custom html tags.

Are there any gulp plugins that can minify html containing custom tags?

2条回答
叼着烟拽天下
2楼-- · 2019-08-12 13:24

Try out gulp-htmlmin.

I use it to minify my elements.html file after vulcanising, but I suppose it should work on non vulcanised elements just as well. Here's how I call the plugin inside my gulpfile:

.pipe(htmlmin({
    removeEmptyAttributes: true,
    customAttrAssign: [{"source":"\\$="}],
    customAttrSurround: [
        [ {"source": "\\({\\{"}, {"source": "\\}\\}"} ],
        [ {"source": "\\[\\["}, {"source": "\\]\\]"}  ]
    ],
    collapseWhitespace: true,
    // always leave one space
    // because http://perfectionkills.com/experimenting-with-html-minifier/#collapse_whitespace
    conservativeCollapse: true,
    minifyJS: true,
    minifyCSS: true,
    removeComments: true,
    removeCommentsFromCDATA: true,
    removeCDATASectionsFromCDATA: true
}))
查看更多
再贱就再见
3楼-- · 2019-08-12 13:25

To do this is quite the challenge. You use the crisper plugin to factor out the script into it's own file. You can then minify the script source. Afterwards use vulcanize to inline your script back into the HTML.

查看更多
登录 后发表回答