-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
171 lines (128 loc) · 4.4 KB
/
gulpfile.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
var gulp = require('gulp');
// ================================================
// Plugins
// ================================================
var livereload = require('gulp-livereload')
var notify = require("gulp-notify")
var autoprefixer = require('autoprefixer')
var combineMq = require('gulp-combine-mq')
var nodeSass = require('node-sass');
var fs = require('fs')
var chokidar = require('chokidar')
var postcss = require('postcss');
var processor = postcss([require('autoprefixer')({ browsers: ['> 1%', 'last 2 versions', 'ie 9', 'android 4', 'Firefox ESR', 'Opera 12.1'] })]);
var iconfont = require('gulp-iconfont');
var iconfontCss = require('gulp-iconfont-css');
var consolidate = require('gulp-consolidate');
//debug for browser support
//var info = autoprefixer({ browsers: ['> 1%', 'last 2 versions', 'ie 9', 'android 4', 'Firefox ESR', 'Opera 12.1'] }).info();
//console.log(info);
var runTimestamp = Math.round(Date.now()/1000);
// ================================================
// Tasks
// ================================================
// Default
gulp.task('default', [
'sass'
]);
gulp.task('font', [
'icon-font',
'sass'
]);
// Production
gulp.task('production', [
'production-sass',
//'combine-media-queries' // nicht ausgereift
]);
// ------------------------------------------------
// Icon-Font
// ------------------------------------------------
var fontName = 'icons';
gulp.task('icon-font', function(){
gulp.src(['img/icons/*.svg'])
.pipe(iconfontCss({
fontName: fontName,
normalize: true,
path: 'scss/core/templates/icon-font.css',
targetPath: '../../scss/page/base/_icons.scss',
fontPath: 'css/webfonts/',
className: 'font',
}))
.pipe(iconfont({
fontName: fontName,
/* normalize and fontHeight only if svgs height < 500px */
normalize: true,
fontHeight: 1001
}))
.pipe(gulp.dest('css/fonts/'));
});
// ------------------------------------------------
// Sass
// ------------------------------------------------
// just sass for development with sourcemaps, autoprefixer, notify
gulp.task('sass', function() {
var cwd = __dirname
livereload.listen();
sassCompiler(cwd + '/scss/main.scss', cwd + '/css/main.css', 'nested', true)
chokidar.watch(cwd + '/scss/**/*', {
ignored: /[\/\\]\./, persistent: true
}).on('change', function(path) {
sassCompiler(cwd + '/scss/main.scss', cwd + '/css/main.css', 'nested', true)
})
});
// compressed CSS
gulp.task('production-sass', function() {
var cwd = __dirname
sassCompiler(cwd + '/scss/main.scss', cwd + '/css/main.css', 'compressed', false)
});
// Combine all Mediaqueries together, prevent css bloat
gulp.task('combine-media-queries', ['production-sass'], function () {
setTimeout(function() {
return gulp.src('css/main.css')
.pipe(combineMq({
beautify: true
}))
.pipe(gulp.dest('css'));
}, 100);
});
// ------------------------------------------------
// Functions
// ------------------------------------------------
var sassCompiler = function(input, output, outputStyle, hasSourcemap) {
nodeSass.render({
file: input,
outputStyle: outputStyle,
outFile: output,
sourceComments: hasSourcemap,
sourceMapEmbed: hasSourcemap,
sourceMapContents: hasSourcemap,
sourceMap: hasSourcemap,
}, function(err, result) {
if (err) {
console.log("SASS: \n");
console.log(err)
console.log("\n");
return notify().write(err.message);
} else {
notify().write('SCSS compiled in ' + result.stats.duration + 'ms');
processor
.process(result.css)
.then(function (result) {
fs.writeFile(output, result.css, function(err) {
livereload.changed('/css/main.css')
});
});
}
});
}
// ------------------------------------------------
// Watch
// ------------------------------------------------
gulp.task('watch', function() {
gulp.watch('scss/**/*.scss', ['sass']);
livereload.listen();
// Watch for changes in 'compiled' files
gulp.watch('css/main.css', function (file) {
livereload.changed(file);
});
});