├── .gitignore ├── .travis.yml ├── index.js ├── license.md ├── package.json └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.12" 4 | 5 | deploy: 6 | provider: npm 7 | email: hola@nathanmac.com 8 | api_key: 9 | secure: uhX8Z6YVjGfPDwoiHRGm7176zwSHQ2HBzixHRVB5ciS1lDjQmdxNMYKHFFOIRn8bN191APBMmUPdfZSbHXQJ2yqh/eVdJKfKLt4RXQcJZ5GZ7wScsCC6uRHL++JxWJVl917v+7pBimIetw6DjnbRrK1+54Ala8QUxkopP4zmlEY= 10 | on: 11 | tags: true 12 | repo: nathanmac/laravel-elixir-imagemin 13 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var changed = require('gulp-changed'); 3 | var imagemin = require('gulp-imagemin'); 4 | var pngquant = require('imagemin-pngquant'); 5 | var _ = require('underscore'); 6 | var elixir = require('laravel-elixir'); 7 | var config = elixir.config; 8 | 9 | /* 10 | |---------------------------------------------------------------- 11 | | ImageMin Processor 12 | |---------------------------------------------------------------- 13 | | 14 | | This task will trigger your images to be processed using 15 | | imagemin processor. 16 | | 17 | | Minify PNG, JPEG, GIF and SVG images 18 | | 19 | */ 20 | elixir.extend('imagemin', function(options) { 21 | 22 | config.images = _.extend({ 23 | folder: 'images', 24 | outputFolder: 'images' 25 | }, config.images || {}); 26 | 27 | options = _.extend({ 28 | progressive: true, 29 | svgoPlugins: [{removeViewBox: false}], 30 | use: [pngquant()] 31 | }, options); 32 | 33 | new elixir.Task('imagemin', function () { 34 | var paths = new elixir.GulpPaths() 35 | .src(config.get('assets.images.folder')) 36 | .output(config.get('public.images.outputFolder')); 37 | 38 | return gulp.src(paths.src.path) 39 | .pipe(changed(paths.output.path)) 40 | .pipe(imagemin(options)) 41 | .on('error', function(e) { 42 | new elixir.Notification().error(e, 'ImageMin Failed!'); 43 | this.emit('end'); 44 | }) 45 | .pipe(gulp.dest(paths.output.path)) 46 | .pipe(new elixir.Notification('ImageMin Complete!')) 47 | }).watch( 48 | [ 49 | config.get('assets.images.folder') + '/**/*.jpg', 50 | config.get('assets.images.folder') + '/**/*.jpeg', 51 | config.get('assets.images.folder') + '/**/*.svg', 52 | config.get('assets.images.folder') + '/**/*.gif', 53 | config.get('assets.images.folder') + '/**/*.png' 54 | ] 55 | ); 56 | }); 57 | -------------------------------------------------------------------------------- /license.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Nathan Macnamara 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. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "laravel-elixir-imagemin", 3 | "version": "0.2.3", 4 | "description": "Laravel Elixir wrapper around imagemin Gulp task.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 0" 8 | }, 9 | "keywords": [ 10 | "gulp", 11 | "laravel", 12 | "elixir", 13 | "imagemin" 14 | ], 15 | "author": "Nathan Macnamara", 16 | "license": "MIT", 17 | "homepage": "https://github.com/nathanmac/laravel-elixir-imagemin", 18 | "bugs": "https://github.com/nathanmac/laravel-elixir-imagemin/issues", 19 | "repository": { 20 | "type": "git", 21 | "url": "https://github.com/nathanmac/laravel-elixir-imagemin" 22 | }, 23 | "dependencies": { 24 | "gulp-changed": "^1.3.0", 25 | "gulp-imagemin": "^3.0.2", 26 | "imagemin-pngquant": "^4.1.2", 27 | "underscore": "^1.8.3" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # laravel-elixir-imagemin 2 | 3 | This is a simple imagemin wrapper around Laravel Elixir. Add it to your Elixir-enhanced Gulpfile, like so: 4 | 5 | ## Install 6 | 7 | ``` 8 | npm install --save-dev laravel-elixir-imagemin 9 | ``` 10 | 11 | ## Usage 12 | 13 | ### Example *Gulpfile*: 14 | 15 | ```javascript 16 | var elixir = require('laravel-elixir'); 17 | 18 | require('laravel-elixir-imagemin'); 19 | 20 | elixir(function(mix) { 21 | mix.imagemin(); 22 | }); 23 | ``` 24 | 25 | This will scan your `resources/assets/images` directory for all image files. 26 | 27 | ### Changing the default image directories 28 | 29 | If you want to process a different image directory, you can update your Elixir config by either: 30 | 31 | #### Defining `elixir.config.images` in your *Gulpfile* 32 | 33 | You can define `elixir.config.images` in your `gulpfile.js` like so: 34 | 35 | ```javascript 36 | var elixir = require('laravel-elixir'); 37 | 38 | require('laravel-elixir-imagemin'); 39 | 40 | elixir.config.images = { 41 | folder: 'img', 42 | outputFolder: 'img' 43 | }; 44 | 45 | elixir(function(mix) { 46 | mix.imagemin(); 47 | }); 48 | ``` 49 | 50 | #### Setting `config.images` in an `elixir.json` file 51 | 52 | You can create an [`elixir.json`](https://github.com/laravel/elixir/blob/dfd6655537eb3294a4c71e826cd0e8a6f6b2108b/index.js#L50-L67) 53 | file in your project root to modify Elixir's default settings. 54 | 55 | ```json 56 | { 57 | "images": { 58 | "folder": "img", 59 | "outputFolder": "img" 60 | } 61 | } 62 | ``` 63 | 64 | #### Upgrading from the old syntax 65 | 66 | If you're upgrading from the old syntax, where you defined custom directories like so: 67 | 68 | ```javascript 69 | mix.imagemin("./resources/assets/img", "public/images/foo/bar/"); 70 | ``` 71 | 72 | All you have to do is: 73 | 74 | - Remove the first two parameters, then 75 | - Follow the instructions for ["Changing the default image directories"](#changing-the-default-image-directories) 76 | 77 | **Note**: You don't define the full path anymore. Instead of `resources/assets/img` you simply use `img`, because 78 | laravel-elixir-imagemin will look inside your `assets` and `public` directories (or whatever else you may have 79 | configured). 80 | 81 | ### Custom imagemin options 82 | 83 | You can override the default imagemin options by passing in an options object like so: 84 | 85 | ```javascript 86 | mix.imagemin({ 87 | optimizationLevel: 3, 88 | progressive: true, 89 | interlaced: true 90 | }); 91 | ``` 92 | 93 | Available imagemin options are listed [here in the gulp-imagemin readme](https://github.com/sindresorhus/gulp-imagemin#imageminoptions). 94 | --------------------------------------------------------------------------------