Skip to content

Instantly share code, notes, and snippets.

@kepek
Last active April 3, 2016 07:35
Show Gist options
  • Save kepek/b0f71eb8292de8015c4f to your computer and use it in GitHub Desktop.
Save kepek/b0f71eb8292de8015c4f to your computer and use it in GitHub Desktop.
Laravel 4 - Gulp / Elixir + Custom Tasks
var elixir = require('laravel-elixir');
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var minify = require('gulp-minify-css');
var _ = require('underscore');
/*
|--------------------------------------------------------------------------
| Uglify Task
|--------------------------------------------------------------------------
*/
elixir.extend('uglify', function(src, outputDir, options) {
src = src || elixir.config.jsOutput + '/*.js';
outputDir = outputDir || elixir.config.jsOutput;
options = _.extend({}, options);
gulp.task('uglify', function() {
gulp.src(src)
.pipe(uglify(options))
.pipe(gulp.dest(outputDir));
});
return this.queueTask('uglify');
});
/*
|--------------------------------------------------------------------------
| Minify Task
|--------------------------------------------------------------------------
*/
elixir.extend('minify', function(src, outputDir, options) {
src = src || elixir.config.cssOutput + '/*.css';
outputDir = outputDir || elixir.config.cssOutput;
options = _.extend({keepSpecialComments: 0}, options);
gulp.task('minify', function() {
gulp.src(src)
.pipe(minify(options))
.pipe(gulp.dest(outputDir));
});
return this.queueTask('minify');
});
{
"srcDir": "app",
"assetsDir": "app/assets/",
"cssOutput": "public/assets/css",
"jsOutput": "public/assets/js",
"bowerDir": "vendor/bower_components"
}
var elixir = require('laravel-elixir');
require('laravel-elixir-browserify');
require('./elixir-custom-tasks');
/*
|--------------------------------------------------------------------------
| Elixir Asset Management
|--------------------------------------------------------------------------
|
| Elixir provides a clean, fluent API for defining some basic Gulp tasks
| for your Laravel application. By default, we are compiling the Sass
| file for our application, as well as publishing vendor resources.
|
| ### Documentation:
|
| https://github.com/laravel/elixir
|
|
| ### Default Tasks:
|
| - coffe
| - events
| - less
| - phpSpec
| - phpUnit
| - publish
| - copy
| - routes
| - sass
| - scripts
| - styles
| - tdd
| - version
| - watch
|
| ### More Tasks:
|
| https://www.npmjs.com/search?q=laravel-elixir
|
|
| ### Execute All Registered Tasks Once
|
| gulp
|
|
| ### Watch Assets for Changes
|
| gulp watch
|
|
| ### Watch Tests and PHP Classes for Changes
|
| gulp tdd
|
*/
elixir(function(mix) {
mix.sass(['main.scss', 'admin.scss'])
.browserify(['main.js', 'admin.js'])
.minify()
.uglify();
});
{
"name": "laravel",
"repository": {},
"dependencies": {},
"devDependencies": {
"gulp": "^3.8.8",
"gulp-minify-css": "^0.3.11",
"gulp-uglify": "^1.0.2",
"laravel-elixir": "*",
"laravel-elixir-browserify": "^0.3.1",
"underscore": "^1.7.0"
},
"engines": {
"node": ">=0.10.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment