-->

How can I minify HTML, CSS and JavaScript files in

2019-03-13 14:46发布

问题:

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

回答1:

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.



回答2:

  • 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



标签: docpad