Minify all of sails.js served html

丶灬走出姿态 提交于 2019-12-04 08:37:28

问题


I need my sails.js app to serve minified html to the user. So it is hard to read by the user. Has anyone done this before ?

Thank you.


回答1:


This works for me: https://github.com/balderdashy/sails/issues/2188#issuecomment-56994236

In config/views.js:

var minify = require('html-minifier').minify;
var ejs = require('ejs-locals');
var parsing = function(path,options,fn) {
    options.locals = options.locals || {};
    options.locals._layoutFile = 'layout.ejs';
    ejs(path, options, function(err, str){
      str = minify(str,{collapseWhitespace: true, removeComments: true});
      return fn(err, str);
    });

};

module.exports.views = {
  engine: {
    ext: 'ejs',
    fn: parsing
  },
  layout: false
};


来源:https://stackoverflow.com/questions/26051280/minify-all-of-sails-js-served-html

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!