-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
57 lines (46 loc) · 1.69 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'use strict';
var _ = require('underscore');
var elixir = require('laravel-elixir');
var gulp = require('gulp');
var gutil = require('gulp-util');
var rename = require('gulp-rename');
var $ = require('gulp-load-plugins')();
var config = elixir.config;
elixir.extend('postcss', function(src, opts) {
var css = config.css;
var name = 'postcss';
var notification = elixir.Notification ? elixir.Notification : require('laravel-elixir/Notification');
opts = _.extend({}, opts);
opts = _.extend({
output: config.publicPath + '/' + config.css.folder,
options: {},
plugins: [],
srcPath: config.assetsPath + '/' + name,
sourcemaps: opts.sourcemaps ? opts.sourcemaps : config.sourcemaps,
watchs: [],
}, opts);
new elixir.Task(name, function() {
var cssnano = css.cssnano ? css.cssnano.pluginOptions : undefined;
var srcPath = opts.srcPath + '/' + src;
var err = function(e) {
// line break
console.log('');
console.log(gutil.colors.bgRed('PostCSS - Error'));
console.log(' - ' + e.message);
};
if(typeof this.recordStep !== 'undefined') {
this.recordStep('Post processing CSS');
this.src = srcPath;
this.output = opts.output;
}
return gulp.src(srcPath)
.pipe($.if(opts.sourcemaps, $.sourcemaps.init()))
.pipe($.postcss(opts.plugins, opts.options).on('error', err))
.pipe($.if(config.production, $.cssnano(cssnano)))
.pipe(rename({ extname: '.css' }))
.pipe($.if(opts.sourcemaps, $.sourcemaps.write('.')))
.pipe(gulp.dest(opts.output))
.pipe(new notification().message(name + ' Compiled!'));
})
.watch(_.union([opts.srcPath + '/**/*.css'], opts.watchs));
});