Skip to content

Instantly share code, notes, and snippets.

@lukrizal
Last active May 10, 2016 19:31
Show Gist options
  • Save lukrizal/29565074f4c312e9188a to your computer and use it in GitHub Desktop.
Save lukrizal/29565074f4c312e9188a to your computer and use it in GitHub Desktop.
var gulp = require('gulp'),
compile = require('./node_modules/laravel-elixir/tasks/shared/Css.js'),
Elixir = require('laravel-elixir'),
Log = Elixir.Log,
fs = require('fs'),
path = require('path'),
config = Elixir.config;
/*
|----------------------------------------------------------------
| Sass Compilation Task
|----------------------------------------------------------------
|
| This task will compile your Sass, including minification and
| and auto-prefixing. Sass is one of the CSS pre-precessors
| supported by Elixir, along with the Less CSS processor.
|
*/
var gulpTask = function (src, output, options) {
var paths = prepGulpPaths(src, output);
new Elixir.Task('sassPerFile', function () {
return compile({
name: 'sassPerFile',
compiler: require('gulp-sass'),
src: paths.src,
output: paths.output,
task: this,
pluginOptions: options || config.css.sass.pluginOptions
});
})
.watch(paths.src.baseDir + '/**/*.+(sass|scss)')
.ignore(paths.output.path);
};
Elixir.extend('sassPerFile', function (src, output, options) {
var paths = prepGulpPaths(src, output);
files = fs.readdirSync(paths.src.baseDir);
files.forEach(function (file) {
var srcFile = paths.src.baseDir + '/' + file;
if (fs.statSync(srcFile).isFile() &&
path.extname(srcFile) == '.scss' &&
file.charAt(0) != '_') {
var outputFile = paths.output.baseDir + '/' + src + '/' + path.basename(file, '.scss') + '.css';
gulpTask.apply(this, [srcFile, outputFile, options]);
}
});
});
/**
* Prep the Gulp src and output paths.
*
* @param {string|Array} src
* @param {string|null} output
* @return {GulpPaths}
*/
var prepGulpPaths = function (src, output) {
return new Elixir.GulpPaths()
.src(src, config.get('assets.css.sass.folder'))
.output(output || config.get('public.css.outputFolder'), 'app.css');
};
var elixir = require('laravel-elixir');
require('./elixir-sass-each-files');
elixir(function (mix) {
var metronicSassFolders = [
'metronic/global',
'metronic/apps',
'metronic/pages',
'metronic/layouts/layout',
'metronic/layouts/layout/themes',
'metronic/layouts/layout/themes',
'metronic/layouts/layout2',
'metronic/layouts/layout2/themes',
'metronic/layouts/layout3',
'metronic/layouts/layout3/themes',
'metronic/layouts/layout4',
'metronic/layouts/layout4/themes',
'metronic/layouts/layout5',
'metronic/layouts/layout6',
'metronic/layouts/layout7'
];
metronicSassFolders.forEach(function (metronicSassFolder) {
mix.sassPerFile(metronicSassFolder, 'resources/assets/css');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment