Uglify/minify Polymer web components using gulp

喜夏-厌秋 提交于 2019-12-14 02:37:54

问题


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?


回答1:


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.




回答2:


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
}))


来源:https://stackoverflow.com/questions/35213647/uglify-minify-polymer-web-components-using-gulp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!