forked from nicholasadamou/starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsass.js
97 lines (92 loc) · 2.68 KB
/
sass.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
var gulp = require('gulp'),
$ = require('gulp-load-plugins')({ lazy: true }),
autoprefixer = require('autoprefixer'),
rucksack = require('rucksack-css'),
bourbon = require('node-bourbon'),
neat = require('node-neat'),
lost = require('lost');
var paths = require('../../paths.js'),
config = require('../../config.js')();
gulp.task('sass', function() {
var env = ((config.environment || process.env.NODE_ENV || 'development').trim().toLowerCase() !== 'production'),
sass = {
sourceComments: (config.sassOptions.sourceComments).trim().toLowerCase() ? !env : '',
outputStyle: (config.sassOptions.outputStyle).trim().toLowerCase() ? !env : 'compressed',
imagePath: config.sassOptions.imagePath,
precision: config.sassOptions.precision || 3,
includePaths: [
bourbon.includePaths,
neat.includePaths
],
errLogToConsole: true
},
plugins = [
lost(),
rucksack(),
autoprefixer({
browsers: [
'> 1%',
'last 2 versions',
'firefox >= 4',
'safari 7',
'safari 8',
'IE 8',
'IE 9',
'IE 10',
'IE 11'
],
}),
];
console.log('-> Compiling SASS for ' + config.environment);
if (env) {
// Select files
gulp.src(`${paths.to.sass.in}/*.scss`)
// Prevent pipe breaking caused by errors from gulp plugins
.pipe($.plumber())
// Initialize sourcemaps
.pipe($.sourcemaps.init())
// Compile Sass
.pipe($.sass(sass).on('error', $.sass.logError))
// Add vendor prefixes
.pipe($.postcss(plugins))
// Concatenate includes
.pipe($.include({
includePaths: [
`${config.root}/bower_components`,
`${config.root}/node_modules`
],
}))
// save sourcemaps
.pipe($.sourcemaps.write(paths.to.sass.out))
// Save unminified file
.pipe(gulp.dest(`${paths.to.sass.out}`))
} else {
// Select files
gulp.src(`${paths.to.sass.in}/*.scss`)
// Prevent pipe breaking caused by errors from gulp plugins
.pipe($.plumber())
// Compile Sass
.pipe($.sass(sass).on('error', $.sass.logError))
// Add vendor prefixes
.pipe($.postcss(plugins))
// Concatenate includes
.pipe($.include({
includePaths: [
`${config.root}/bower_components`,
`${config.root}/node_modules`
],
}))
// Show file-size before compression
.pipe($.size({ title: 'sass In Size' }))
// Optimize and minify
.pipe($.cssnano())
// Show file-size after compression
.pipe($.size({ title: 'sass Out Size' }))
// Append suffix
.pipe($.rename({
suffix: '.min',
}))
// Save minified file
.pipe(gulp.dest(`${paths.to.sass.out}`))
}
});