'How can I have Minify/uglify inline JavaScript using Pug?
I am using Pug for a web page that I am building.
At the end of a module I have a script.
tag (the regular script
tag cannot be used because it isn't compatible with 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? I have not figured out how to use filters (Uglify JS) on the script.
tag.
Solution 1:[1]
Script: uglify-js
// load more videos
$("#btn-more").click(() => {
$.get(`#{lang}/videos?quantity=#{numVideos + 2}`)
.done((videos) => {
$(videos).ready(() => {
$("#videos").replaceWith(videos)
})
})
})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Laurel |