Jade、EJS、JSHTML、Mustache、Handlebars 五大node模板引擎區別
阿新 • • 發佈:2019-01-08
Here’s my feature matrix I used while comparing.
Built into Express | Allows logic in templates | Encourages logic in templates | Reuse templates client side | Allows Bootstrap Integration | IDE Support | Partials | Notes | |
Jade | yes | yes | no | No | Yes | Webstorm, sublime with add-in | Yes + Layout | Default for Express. Lots of add-ons available via npm. Documentation is incomplete but passable. Very clean syntax. Easily readable. |
EJS | yes | yes | yes | yes | Yes | Webstorm, sublime with add-in | No | Default for Sails.js. Very messy syntax. |
JSHTML | yes but no | yes | no | ??? | ??? | ??? | No | Appears to be built in but isn’t. Instead need jshtml-express. No partials support. Missing variable in template is fatal error. Website is outdated. Automated tests are failing. Difficult to find documentation. Seeks to be familar to .net developers. |
Mustache | yes (older version of hogan) | no | no | yes | yes | Webstorm with plugin, sublime with plugin | Yes | Very popular client-side templating library, supported by many languages. Using logic-less templates can be frustrating at first |
Handlebars | no, use express3-handlebars | no | no | yes | yes | Webstorm with plugin, sublime with plugin | Yes + Layout | Template engine used by Ghost. Very popular client side library, superset of Mustache. Supports an easier to understand if syntax for those who want minimal logic. |