-
Notifications
You must be signed in to change notification settings - Fork 44
Laravel 5 5.1 HTML Minifying
Krisan Alfa Timur edited this page Mar 21, 2016
·
6 revisions
I recommend using Gulp, instead of a PHP package, to compress the HTML that gets generated by your Blade template files. It works very well and is very configurable. It uses gulp-htmlmin, which uses html-minifier.
var htmlmin = require('gulp-htmlmin');
var gulp = require('gulp');
gulp.task('compress', function() {
var opts = {
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true,
minifyJS: true
};
return gulp.src('./storage/framework/views/*')
.pipe(htmlmin(opts))
.pipe(gulp.dest('./storage/framework/views/'));
});
var elixir = require('laravel-elixir'),
gulp = require('gulp'),
htmlmin = require('gulp-htmlmin');
elixir.extend('compress', function() {
new elixir.Task('compress', function() {
return gulp.src('./storage/framework/views/*')
.pipe(htmlmin({
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true,
minifyJS: true,
}))
.pipe(gulp.dest('./storage/framework/views/'));
})
.watch('./storage/framework/views/*');
});
Be sure you add your task in Elixir task list:
elixir(function(mix) {
mix.compress();
});
$ gulp compress