[英]How can I have Minify/uglify inline JavaScript using Pug?
I am using Pug for a web page that I am building.我正在将 Pug 用于我正在构建的网页。 At the end of a module I have a
script.
在模块的末尾,我有一个
script.
tag (the regular script
tag cannot be used because it isn't compatible with jQuery):标记(不能使用常规
script
标记,因为它与 jQuery 不兼容):
script.
// load more videos
$("#btn-more").click(() => {
$.get(`#{lang}/videos?quantity=#{numVideos + 2}`)
.done((videos) => {
$(videos).ready(() => {
$("#videos").replaceWith(videos)
})
})
})
Which ends up producing code that is not minified:最终生成未缩小的代码:
<script>// load more videos
$("#btn-more").click(() => {
$.get(`en/videos?quantity=6`)
.done((videos) => {
$(videos).ready(() => {
$("#videos").replaceWith(videos)
})
})
})</script>
Is there a way to have Pug minify the code?有没有办法让 Pug 缩小代码? I have not figured out how to use filters (Uglify JS) on the
script.
我还没有弄清楚如何在
script.
tag.标签。
Script: uglify-js脚本:uglify-js
// load more videos
$("#btn-more").click(() => {
$.get(`#{lang}/videos?quantity=#{numVideos + 2}`)
.done((videos) => {
$(videos).ready(() => {
$("#videos").replaceWith(videos)
})
})
})
npm i jstransformer-uglify-js
:uglify-js
filter.:uglify-js
过滤器呈现以下模板。script: :uglify-js
$("#btn-more").click(() => {
$.get(`#{lang}/videos?quantity=#{numVideos + 2}`)
.done((videos) => {
$(videos).ready(() => {
$("#videos").replaceWith(videos)
})
})
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.