-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgulpfile.js
183 lines (162 loc) · 4.51 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
'use strict';
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var jadeData = require('./data.json');
var autoprefixer = require('autoprefixer');
const SRC = 'src'
const DEST = 'docs'
var config = {
jsConcat: [
'node_modules/svg4everybody/dist/svg4everybody.min.js',
'node_modules/tablesort/dist/tablesort.min.js',
'node_modules/tablesort/dist/sorts/tablesort.number.min.js',
`./${SRC}/vendors/lazyload.min.js`,
`./${SRC}/vendors/tooltip/popper.min.js`,
`./${SRC}/vendors/tooltip/tippy.all.min.js`,
`./${SRC}/vendors/tingle/tingle.min.js`,
`./${SRC}/vendors/smooth-scroll.polyfills.min.js`,
`./${SRC}/vendors/swiper/js/swiper.min.js`,
`./${SRC}/vendors/headroom.min.js`,
`./${SRC}/vendors/rss-parser.min.js`,
`./${SRC}/vendors/lodash.min.js`,
],
browserSync: {
reloadOnRestart: true,
notify: false,
port: 9000,
startPath: "/",
server: {
baseDir: [`${DEST}`, `${SRC}`]
}
}
}
var jsDest = `${DEST}/scripts`;
// compile jade
gulp.task('views', function() {
return gulp.src([`${SRC}/templates/**/*.jade`])
.pipe($.plumber())
//only pass unchanged *main* files and *all* the partials
.pipe($.changed(`${DEST}`, { extension: '.html' }))
//filter out unchanged partials, but it only works when watching
.pipe($.if(browserSync.active, $.cached('jade')))
//find files that depend on the files that have changed
.pipe($.jadeInheritance({ basedir: `${SRC}/templates` }))
//filter out partials (folders and files starting with "_" )
.pipe($.filter(function(file) {
return !/\_/.test(file.path) && !/^_/.test(file.relative);
}))
.pipe($.jade({
locals: jadeData,
pretty: false
}))
.pipe($.beml({
elemPrefix: '__',
modPrefix: '--',
modDlmtr: '-'
}))
.pipe($.fileInclude({ basepath: `${DEST}` }))
.pipe($.htmlPrettify({ indent_char: ' ', indent_size: 1 }))
.pipe(gulp.dest(`${DEST}`))
.pipe(reload({ stream: true }));
});
// compile sass
gulp.task('styles', function() {
$.rubySass(`${SRC}/styles`, {
style: 'compact', //compact, compressed, expanded
precision: 10,
sourcemap: true
})
.on('error', function(err) {
console.error('Error!', err.message);
})
.pipe($.postcss( [autoprefixer()] ))
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest(`${DEST}/styles`))
.pipe(reload({ stream: true }));
});
// view and check scripts
gulp.task('scripts', function() {
return gulp.src([`${SRC}/scripts/**/*.js`, `!${SRC}/scripts/modernizr/modernizr.custom.js`])
.pipe($.filter(function(file) {
return !/\_/.test(file.path) && !/^_/.test(file.relative);
}))
.pipe($.plumber())
.pipe($.sourcemaps.init())
.pipe($.babel({
presets: ['es2015']
}))
.pipe($.uglify())
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest(jsDest));
});
// concat scripts
gulp.task('concat-scripts', function() {
return gulp.src(config.jsConcat)
.pipe($.concat('vendors.js'))
.pipe(gulp.dest(jsDest))
});
// sprite-gen
gulp.task('png-sprite', function() {
var spriteData = gulp.src(`${SRC}/img/sprite/raster/*.png`).pipe($.spritesmith({
imgName: 'sprite.png',
cssName: `../../../${SRC}/styles/core/_sprite.scss`,
padding: 20,
imgPath: '../img/theme/sprite.png'
}));
return spriteData.pipe(gulp.dest(`${DEST}/img/theme/`));
});
// SVG sprite
gulp.task('svg-sprite', function() {
gulp.src(`${SRC}/img/sprite/svg/*.svg`)
.pipe($.plumber())
.pipe($.svgSprite({
shape: {
dimension: {
maxWidth: 32,
maxHeight: 32
},
spacing: {
padding: 0
},
id: {
generator: 'si-'
}
},
mode: {
symbol: {
sprite: "../sprite.symbol.svg"
}
}
})).on('error', function(error) { console.log(error); })
.pipe(gulp.dest(`${DEST}/img/theme`));
});
// main task
gulp.task('serve', $.sync(gulp).sync([
['views', 'png-sprite', 'styles', 'scripts', 'concat-scripts', 'svg-sprite']
]), function() {
browserSync.init(config.browserSync);
// watch for changes
gulp.watch([
`${DEST}/scripts/**/*.js`,
`${SRC}/img/**/*`
]).on('change', reload);
gulp.watch(`${SRC}/scripts/**/*.js`, ['scripts']);
gulp.watch(`${SRC}/plugins/**/*.js`, ['concat-scripts']);
gulp.watch(`${SRC}/styles/**/*.scss`, ['styles']);
gulp.watch(`${SRC}/**/*.jade`, ['views']);
gulp.watch(`${SRC}/img/sprite/**/*.png`, ['png-sprite']);
gulp.watch(`${SRC}/img/sprite/**/*.svg`, ['svg-sprite', 'views']);
});
gulp.task('build', [
'svg-sprite',
'png-sprite',
'views',
'styles',
'scripts',
'concat-scripts',
]);
gulp.task('default', function() {
gulp.start('serve');
});