├── .gitignore ├── LICENSE ├── README.md ├── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Honoré Hounwanou 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel Elixir HTML minify 2 | 3 | This package allows you to minify static HTML files or the HTML that gets generated by your Blade template files. It works very well and is very configurable. It uses [gulp-htmlmin](https://github.com/jonschlinkert/gulp-htmlmin), which uses [html-minifier](https://github.com/kangax/html-minifier). 4 | 5 | ## Installation 6 | 7 | First you need to install this package. 8 | 9 | ```sh 10 | npm install --save-dev laravel-elixir-minify-html 11 | ``` 12 | 13 | Then require this package into your `gulpfile.js`. 14 | 15 | ```js 16 | var Elixir = require('laravel-elixir'); 17 | require('laravel-elixir-minify-html'); 18 | ``` 19 | 20 | Then call the `html` method from your mix. 21 | 22 | The `html` method can take up to three arguments: 23 | 24 | 1. `src` (required): The files to minify. 25 | 2. `outputPath` (optional): The output folder (defaults to `storage/framework/views`). 26 | 3. `options` (optional): Options object passed to the `gulp-htmlmin` task. 27 | 28 | This task defines a watcher for the path defined in `src`. 29 | 30 | Sample code: 31 | 32 | ```js 33 | Elixir(function(mix) { 34 | mix.html('storage/framework/views/*', 'storage/framework/views/', {collapseWhitespace: true, removeAttributeQuotes: true, removeComments: true, minifyJS: true}); 35 | }); 36 | ``` -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var elixir = require('laravel-elixir'); 3 | var htmlmin = require('gulp-htmlmin'); 4 | 5 | /** 6 | * Minify static html pages, useful when using html partials loaded though ajax 7 | * @param {string} src The files to minify 8 | * @param {string|object} outputPath The output path, or an options object 9 | * @param {object} options The options object passed to the minify task 10 | */ 11 | elixir.extend('html', function(src, outputPath, options) { 12 | // If the options object was provided on the outputPath parameter 13 | if (typeof outputPath == 'object') { 14 | options = outputPath; 15 | outputPath = null; 16 | } 17 | 18 | // Parse the source and output paths 19 | src = src || 'storage/framework/views/*'; 20 | outputPath = outputPath || 'storage/framework/views/'; 21 | 22 | var paths = { 23 | src: src, 24 | outputPath: outputPath 25 | }; 26 | 27 | options = typeof options == 'undefined' ? {} : options; 28 | 29 | new elixir.Task('minify', function() { 30 | var minifyOptions = options; 31 | 32 | return gulp.src(paths.src) 33 | .pipe(htmlmin(minifyOptions)) 34 | .pipe(gulp.dest(paths.outputPath)) 35 | .pipe(new elixir.Notification('HTML Minified!')); 36 | }) 37 | // Register watcher for source path 38 | .watch(paths.src); 39 | 40 | }); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "laravel-elixir-minify-html", 3 | "version": "1.0.5", 4 | "description": "Minify the HTML that gets generated by your Blade template files or just static HTML files with Laravel Elixir.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Honoré Hounwanou ", 10 | "license": "MIT", 11 | "dependencies": { 12 | "gulp": "^3.9.1", 13 | "gulp-htmlmin": "^2.0.0" 14 | }, 15 | "repository": { 16 | "type": "git", 17 | "url": "https://github.com/mercuryseries/laravel-elixir-minify-html" 18 | }, 19 | "keywords": [ 20 | "laravel", 21 | "elixir", 22 | "html-minify", 23 | "laravel-elixir-minify-html", 24 | "minify blade files", 25 | "minify static html" 26 | ] 27 | } --------------------------------------------------------------------------------