I try use a middleware to gzip ,like express's compression middleware ,but it did'nt work :(
done with:
var compress = require('compression');
var browserSync = require('browser-sync');
browserSync({
server: {
baseDir: './',
middleware: function(req,res,next){
var gzip = compress();
gzip(req,res,next);
}
}
})
Thanks @suhaotian :)
var compress = require('compression');
var browserSync = require('browser-sync');
browserSync({
server: {
baseDir: './',
middleware: [compress()]
}
})
@ngryman :)
@shakyShane nice work!!
@shakyShane This seems to compress everything except for html files. My settings is through a proxy though:
var compress = require('compression');
var browserSync = require('browser-sync').create();
browserSync.init({
proxy: {
target: "localhost:3000",
middleware: [compression()]
},
port: 10000
});
Sorry, I don鈥檛 understand how to think in order to work. Help.
browserSync: {
serverSyncDev: {
bsFiles: {
src: ['build/*.html', 'build/css/*.css', 'build/js/*.js'],
},
options: {
server: 'build/',
watchTask: true,
},
},
},
compress: {
dist: {
options: {
mode: 'gzip'
},
expand: true,
cwd: 'build/',
src: ['**/*'],
dest: 'build/'
}
},
// Multiple Global Middlewares
middleware: [
function (req, res, next) {
/** First middleware handler **/
},
function (req, res, next) {
/** Second middleware handler **/
}
]
// Per-route middleware
// NOTE: requires v2.12.1
middleware: [
{
route: "/api",
handle: function (req, res, next) {
// handle any requests at /api
}
}
]
// Per-route + global middleware
// NOTE: requires v2.12.1
middleware: [
require("compression")(), // global
{
route: "/api", // per-route
handle: function (req, res, next) {
// handle any requests at /api
}
}
]
var compress = require('compression'); var browserSync = require('browser-sync'); browserSync({ server: { baseDir: './', middleware: [compress()] } })
Hi, @shakyShane. Can you explain why you put the function compress() inside the brackets or recommend some articles about it?
Thank you!
var compress = require('compression'); var browserSync = require('browser-sync'); browserSync({ server: { baseDir: './', middleware: [compress()] } })Hi, @shakyShane. Can you explain why you put the function compress() inside the brackets or recommend some articles about it?
Thank you!
@vicckm Probably you already know the answer by now, but that's because you can pass multiple middlewares to the server. It's inside brackets because it's an array.
Most helpful comment