breezewish / express-minify

Automatically minify and cache your javascript and css files.
https://npmjs.org/package/express-minify
MIT License
86 stars 18 forks source link

CSS are minified, JS not #55

Closed WoodySlum closed 6 years ago

WoodySlum commented 6 years ago

Hi,

As the title explained, CSS are well minified, but the JS files are not :(

const minify = require("express-minify");
const uglifyEs = require("uglify-es");

this.app.use(BodyParser.json({limit: "2mb"}));
this.app.use(BodyParser.urlencoded({ extended: false }));
this.app.use(ENDPOINT_UI, express.static(__dirname + "/../../../ui"));

if (this.enableCompression) {
    this.app.use(compression({filter: (req, res) => {
        if (req.headers["x-no-compression"]) {
            // don't compress responses with this request header
            return false;
        }

        // fallback to standard filter function
        return compression.filter(req, res);
    }}));
}

// Minify
this.app.use(minify({
  cache: false,
  uglifyJsModule: uglifyEs,
  errorHandler: (errorInfo, callback) => {
      Logger.err(errorInfo);
  },
  jsMatch: /javascript/,
  cssMatch: /css/,
  jsonMatch: false
}));

My js files are set under ui/js/ and in the browser I can see that http://localhost:8100/js/bootstrap.js sent the good mime type

Any clue ?

WoodySlum commented 6 years ago

For an unknown reason it's working tonight. Just inverted stuff :

const minify = require("express-minify");
const uglifyEs = require("uglify-es");

if (this.enableCompression) {
    this.app.use(compression({filter: (req, res) => {
        if (req.headers["x-no-compression"]) {
            // don't compress responses with this request header
            return false;
        }

        // fallback to standard filter function
        return compression.filter(req, res);
    }}));
}

// Minify
this.app.use(minify({
  cache: false,
  uglifyJsModule: uglifyEs,
  errorHandler: (errorInfo, callback) => {
      Logger.err(errorInfo);
  },
  jsMatch: /javascript/,
  cssMatch: /css/,
  jsonMatch: false
}))

this.app.use(BodyParser.json({limit: "2mb"}));
this.app.use(BodyParser.urlencoded({ extended: false }));
this.app.use(ENDPOINT_UI, express.static(__dirname + "/../../../ui"));