Minify all of sails.js served html

前端 未结 1 1106
误落风尘
误落风尘 2021-02-04 15:25

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条回答
  •  隐瞒了意图╮
    2021-02-04 15:55

    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
    };
    

    0 讨论(0)
提交回复
热议问题