Created
June 19, 2015 08:13
-
-
Save Anahkiasen/fbf17927a69cefd84f9d to your computer and use it in GitHub Desktop.
Modularized Gulp stack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var config = {}; | |
////////////////////////////////////////////////////////////////////// | |
/////////////////////////////// PATHS //////////////////////////////// | |
////////////////////////////////////////////////////////////////////// | |
// Paths | |
////////////////////////////////////////////////////////////////////// | |
config.paths = { | |
app : __dirname + '/../app', | |
compiled : __dirname + '/../public/app', | |
production: __dirname + '/../public/builds', | |
views : __dirname + '/../resources/views', | |
base : __dirname + '/../resources/assets', | |
}; | |
config.paths.original = { | |
css : config.paths.compiled + '/css', | |
js : config.paths.compiled + '/js', | |
ts : config.paths.base + '/ts', | |
sass : config.paths.base + '/sass', | |
templates: config.paths.compiled + '/templates', | |
}; | |
config.paths.compiled = { | |
css: config.paths.production + '/css', | |
js : config.paths.production + '/js', | |
}; | |
// Files | |
////////////////////////////////////////////////////////////////////// | |
config.files = { | |
php : config.paths.app + '/**/*.php', | |
css : config.paths.original.css + '/**/*.css', | |
sass : config.paths.original.sass + '/**/*.scss', | |
js : config.paths.original.js + '/**/*.js', | |
ts : config.paths.original.ts + '/**/*.ts', | |
templates: config.paths.original.templates + '/**/*.html', | |
twig : config.paths.views + '/**/*.twig', | |
}; | |
////////////////////////////////////////////////////////////////////// | |
/////////////////////////////// TASKS //////////////////////////////// | |
////////////////////////////////////////////////////////////////////// | |
config.tasks = {}; | |
// Assets | |
////////////////////////////////////////////////////////////////////// | |
config.tasks.typescript = { | |
removeComments: true, | |
sourcemap : true, | |
target : 'ES5' | |
}; | |
config.tasks.clean = [ | |
config.paths.compiled.css, | |
config.paths.compiled.js, | |
config.paths.production, | |
]; | |
// Compression | |
////////////////////////////////////////////////////////////////////// | |
config.tasks.uglify = { | |
mangle : true, | |
compress : true, | |
preserveComments: false, | |
}; | |
config.tasks.ngtemplates = { | |
filename: 'templates.js', | |
path : function (path, base) { | |
return path.replace(base, '').replace('public/', '/'); | |
}, | |
htmlmin : { | |
collapseBooleanAttributes : true, | |
collapseWhitespace : true, | |
removeAttributeQuotes : true, | |
removeComments : true, | |
removeEmptyAttributes : true, | |
removeRedundantAttributes : true, | |
removeScriptTypeAttributes : true, | |
removeStyleLinkTypeAttributes: true | |
} | |
}; | |
// Linters | |
////////////////////////////////////////////////////////////////////// | |
config.tasks.csscss = { | |
compass : true, | |
ignoreSassMixins : true, | |
minMatch : 10, | |
failWhenDuplicates: false, | |
verbose : true, | |
}; | |
config.tasks.scsslint = { | |
config: __dirname + '/.scss-lint.yml', | |
}; | |
config.tasks.tslint = { | |
configuration: {}, | |
}, | |
}; | |
module.exports = config; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var elixir = require('laravel-elixir'), | |
config = require('./.gulp/config'), | |
$ = require('gulp-load-plugins')(), | |
run = require('run-sequence'), | |
gulp = require('gulp'); | |
require('./.gulp/tasks.js'); | |
/* | |
|-------------------------------------------------------------------------- | |
| 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. | |
| | |
*/ | |
elixir(function (mix) { | |
mix.task('sass', config.files.sass); | |
mix.task('typescript', config.files.ts); | |
}); | |
gulp.task('rebuild', function () { | |
run( | |
'clean', | |
'default' | |
); | |
}); | |
gulp.task('lint', [ | |
'phplint', | |
'scsslint', | |
'tslint', | |
'csscss', | |
]); | |
gulp.task('production', function (callback) { | |
run( | |
'clean', | |
['sass', 'typescript'], | |
['cssmin', 'uglify', 'ngtemplates'], | |
callback | |
); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'); | |
var config = require('./config.js'); | |
var glob = require('glob'); | |
var path = require('path'); | |
var plugins = require('gulp-load-plugins')(); | |
var elixir = require("laravel-elixir"); | |
// Load all tasks definitions found | |
glob.sync('./.gulp/*/*.js').forEach(function (task) { | |
var key = path.basename(task, '.js'); | |
var folder = path.dirname(task).replace('./.gulp', ''); | |
gulp.task(key, require('.' + folder + '/' + key + '.js')(gulp, config, plugins)); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function (gulp, config, $) { | |
return function () { | |
return gulp.src(config.files.ts) | |
.pipe($.plumber()) | |
.pipe($.sourcemaps.init()) | |
.pipe($.typescript(config.tasks.typescript)) | |
.pipe($.sourcemaps.write()) | |
.pipe(gulp.dest(config.paths.original.js)); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment