How can I minify HTML, CSS and JavaScript files in

2019-03-13 14:06发布

I would like to minify HTML, CSS and JavaScript files when I hit docpad generate, how can I do that?

标签: docpad
2条回答
我只想做你的唯一
2楼-- · 2019-03-13 14:57

There are a few ways you can go about this. The most prominent and most immediate way is to modify your docpad configuration file to trigger an external tool like grunt to minify your assets via the grunt minify task. Here is a gist that showcases this.

Alternatively, there is also Cloudflare which is an amazing website DNS server that also acts as a CDN for your website's content, and minifies your assets automatically post-deployment. Read more here.

Also, while it isn't minify related, you can also concatenate your scripts with Browserify using this gist. Grunt also has a more straightfoward way of concatenating as well via the grunt concat task.

Eventually, perhaps plugins will do this automatically, but considering the fickleness with concatination it could be a while.

查看更多
女痞
3楼-- · 2019-03-13 15:03
  • Use gruntjs for JS files. (Grunt will hook up into docpad generate)
  • Use grunt-contrib-mincss for css files.
  • Use grunt-contrib-htmlmin for html files.
  • Use grunt-compress for compressing all files.

For list of all grunt plugins look here: https://github.com/gruntjs

查看更多
登录 后发表回答