forked from themesberg/pixel-bootstrap-ui-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
executable file
·257 lines (229 loc) · 7.45 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/**
* Gulp file to automate the various tasks
*/
var autoprefixer = require('gulp-autoprefixer');
var browserSync = require('browser-sync').create();
var cleanCss = require('gulp-clean-css');
var del = require('del');
const htmlmin = require('gulp-htmlmin');
const cssbeautify = require('gulp-cssbeautify');
var gulp = require('gulp');
const npmDist = require('gulp-npm-dist');
var sass = require('gulp-sass');
var wait = require('gulp-wait');
var sourcemaps = require('gulp-sourcemaps');
var fileinclude = require('gulp-file-include');
// Define paths
const paths = {
dist: {
base: './dist/',
css: './dist/css',
html: './dist/html',
assets: './dist/assets',
img: './dist/assets/img',
vendor: './dist/vendor'
},
dev: {
base: './html&css/',
css: './html&css/css',
html: './html&css/html',
assets: './html&css/assets',
img: './html&css/assets/img',
vendor: './html&css/vendor'
},
base: {
base: './',
node: './node_modules'
},
src: {
base: './src/',
css: './src/css',
html: './src/html/**/*.html',
assets: './src/assets/**/*.*',
partials: './src/partials/**/*.html',
scss: './src/scss',
node_modules: './node_modules/',
vendor: './vendor'
},
temp: {
base: './.temp/',
css: './.temp/css',
html: './.temp/html',
assets: './.temp/assets',
vendor: './.temp/vendor'
}
};
// Compile SCSS
gulp.task('scss', function () {
return gulp.src([paths.src.scss + '/pixel/**/*.scss', paths.src.scss + '/pixel.scss'])
.pipe(wait(500))
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
overrideBrowserslist: ['> 1%']
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.temp.css))
.pipe(browserSync.stream());
});
gulp.task('index', function () {
return gulp.src([paths.src.base + '**.html'])
.pipe(fileinclude({
prefix: '@@',
basepath: './src/partials/'
}))
.pipe(gulp.dest(paths.temp.base))
.pipe(browserSync.stream());
});
gulp.task('html', function () {
return gulp.src([paths.src.html])
.pipe(fileinclude({
prefix: '@@',
basepath: './src/partials/'
}))
.pipe(gulp.dest(paths.temp.html))
.pipe(browserSync.stream());
});
gulp.task('assets', function () {
return gulp.src([paths.src.assets])
.pipe(gulp.dest(paths.temp.assets))
.pipe(browserSync.stream());
});
gulp.task('vendor', function() {
return gulp.src(npmDist(), { base: paths.src.node_modules })
.pipe(gulp.dest(paths.temp.vendor));
});
gulp.task('serve', gulp.series('scss', 'html', 'index', 'assets', 'vendor', function() {
browserSync.init({
server: paths.temp.base
});
gulp.watch([paths.src.scss + '/pixel/**/*.scss', paths.src.scss + '/pixel.scss'], gulp.series('scss'));
gulp.watch([paths.src.html, paths.src.base + '**.html', paths.src.partials], gulp.series('html', 'index'));
gulp.watch([paths.src.assets], gulp.series('assets'));
gulp.watch([paths.src.vendor], gulp.series('vendor'));
}));
// Beautify CSS
gulp.task('beautify:css', function () {
return gulp.src([
paths.dev.css + '/pixel.css'
])
.pipe(cssbeautify())
.pipe(gulp.dest(paths.dev.css))
});
// Minify CSS
gulp.task('minify:css', function () {
return gulp.src([
paths.dist.css + '/pixel.css'
])
.pipe(cleanCss())
.pipe(gulp.dest(paths.dist.css))
});
// Minify Html
gulp.task('minify:html', function () {
return gulp.src([paths.dist.html + '/**/*.html'])
.pipe(htmlmin({
collapseWhitespace: true
}))
.pipe(fileinclude({
prefix: '@@',
basepath: './src/partials/'
}))
.pipe(gulp.dest(paths.dist.html))
});
gulp.task('minify:html:index', function () {
return gulp.src([paths.dist.base + '*.html'])
.pipe(htmlmin({
collapseWhitespace: true
}))
.pipe(fileinclude({
prefix: '@@',
basepath: './src/partials/'
}))
.pipe(gulp.dest(paths.dist.base))
});
// Clean
gulp.task('clean:dist', function () {
return del([paths.dist.base]);
});
gulp.task('clean:dev', function () {
return del([paths.dev.base]);
});
// Compile and copy scss/css
gulp.task('copy:dist:css', function () {
return gulp.src([paths.src.scss + '/pixel/**/*.scss', paths.src.scss + '/pixel.scss'])
.pipe(wait(500))
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
overrideBrowserslist: ['> 1%']
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.dist.css))
});
gulp.task('copy:dev:css', function () {
return gulp.src([paths.src.scss + '/pixel/**/*.scss', paths.src.scss + '/pixel.scss'])
.pipe(wait(500))
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
overrideBrowserslist: ['> 1%']
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.dev.css))
});
// Copy Html
gulp.task('copy:dist:html', function () {
return gulp.src([paths.src.html])
.pipe(fileinclude({
prefix: '@@',
basepath: './src/partials/'
}))
.pipe(gulp.dest(paths.dist.html));
});
gulp.task('copy:dev:html', function () {
return gulp.src([paths.src.html])
.pipe(fileinclude({
prefix: '@@',
basepath: './src/partials/'
}))
.pipe(gulp.dest(paths.dev.html));
});
// Copy index
gulp.task('copy:dist:html:index', function () {
return gulp.src([paths.src.base + '**.html'])
.pipe(fileinclude({
prefix: '@@',
basepath: './src/partials/'
}))
.pipe(gulp.dest(paths.dist.base))
});
gulp.task('copy:dev:html:index', function () {
return gulp.src([paths.src.base + '**.html'])
.pipe(fileinclude({
prefix: '@@',
basepath: './src/partials/'
}))
.pipe(gulp.dest(paths.dev.base))
});
// Copy assets
gulp.task('copy:dist:assets', function () {
return gulp.src(paths.src.assets)
.pipe(gulp.dest(paths.dist.assets))
});
gulp.task('copy:dev:assets', function () {
return gulp.src(paths.src.assets)
.pipe(gulp.dest(paths.dev.assets))
});
// Copy node_modules to vendor
gulp.task('copy:dist:vendor', function() {
return gulp.src(npmDist(), { base: paths.src.node_modules })
.pipe(gulp.dest(paths.dist.vendor));
});
gulp.task('copy:dev:vendor', function() {
return gulp.src(npmDist(), { base: paths.src.node_modules })
.pipe(gulp.dest(paths.dev.vendor));
});
gulp.task('build:dev', gulp.series('clean:dev', 'copy:dev:css', 'copy:dev:html', 'copy:dev:html:index', 'copy:dev:assets', 'beautify:css', 'copy:dev:vendor'));
gulp.task('build:dist', gulp.series('clean:dist', 'copy:dist:css', 'copy:dist:html', 'copy:dist:html:index', 'copy:dist:assets', 'minify:css', 'minify:html', 'minify:html:index', 'copy:dist:vendor'));
// Default
gulp.task('default', gulp.series('serve'));