缩小所有sails.js服务html

Sah*_*han 8 sails.js

我需要我的sails.js应用程序为用户提供缩小的html.因此用户很难阅读.有没有人这样做过?

谢谢.

Mar*_*ira 13

这对我有用:https: //github.com/balderdashy/sails/issues/2188#issuecomment-56994236

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
};
Run Code Online (Sandbox Code Playgroud)

  • 我们如何将它用于多种布局? (2认同)