-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
172 lines (155 loc) · 4.03 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
var gulp = require('gulp');
var sass = require('gulp-sass');
var plumber = require('gulp-plumber');
var postcss = require('gulp-postcss');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('autoprefixer');
var lost = require('lost');
var notify = require('gulp-notify');
var fileinclude = require('gulp-file-include');
var imagemin = require('gulp-imagemin');
var pngquant = require('imagemin-pngquant');
var browserify = require('browserify');
var vueify = require('vueify');
var debowerify = require('debowerify');
var deamdify = require('deamdify');
var source = require('vinyl-source-stream');
var concat = require('gulp-concat');
var del = require('del');
var browserSync = require('browser-sync').create();
var onError = notify.onError({
message: 'Error: <%= error.message %>'
});
var src = {
scss: 'src/scss/**/*.scss',
scssExternal: '../data/*.scss',
js: ['src/js/*.js', 'src/js/components/**/*.vue', '../data/*.js'],
jsApp: 'src/js/app.js',
jsVendor: 'src/js/vendor/*.js',
img: '../media/img/**/*.{png,jpg,jpeg}',
audio: '../media/audio/*.*',
video: '../media/video/*.*',
font: 'src/font/**.*',
html: 'src/*.html',
favicon: 'src/favicon.ico',
partials: 'src/partials/*.html'
};
var dist = {
css: '../../dist/css',
js: '../../dist/js',
img: '../../dist/img',
audio: '../../dist/audio',
video: '../../dist/video',
font: '../../dist/font',
html: '../../dist'
};
// Compile sass into CSS
gulp.task('scss', function() {
return gulp.src(src.scss)
.pipe(sourcemaps.init())
.pipe(plumber({
errorHandler: onError
}))
.pipe(sass())
.pipe(plumber.stop())
.pipe(notify({
title: "Scss",
message: "Styles compiled successfully",
onLast: true
}))
.pipe(postcss([
lost(),
autoprefixer({
browsers: ['last 2 versions']
})
]))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(dist.css))
.pipe(browserSync.stream({
match: '**/*.css'
}));
});
// Markup
gulp.task('build', function() {
return gulp.src(src.html)
.pipe(fileinclude({
prefix: '@@',
basepath: '@file',
indent: true
}))
.pipe(gulp.dest(dist.html));
});
gulp.task('rebuild', ['build'], function() {
browserSync.reload();
});
// Fonts
gulp.task('fonts', function() {
return gulp.src(src.font)
.pipe(gulp.dest(dist.font))
});
// Favicon
gulp.task('favicon', function() {
return gulp.src(src.favicon)
.pipe(gulp.dest(dist.html))
});
// Images
gulp.task('images', function() {
return gulp.src(src.img)
.pipe(imagemin({
progressive: true,
svgoPlugins: [{
removeViewBox: false
}],
use: [pngquant()]
}))
.pipe(gulp.dest(dist.img));
});
// Audio
gulp.task('audio', function() {
return gulp.src(src.audio)
.pipe(gulp.dest(dist.audio))
});
// Video
gulp.task('video', function() {
return gulp.src(src.video)
.pipe(gulp.dest(dist.video))
});
// Vendor scripts
gulp.task('vendor', function() {
return gulp.src(src.jsVendor)
.pipe(concat('vendor.js'))
.pipe(gulp.dest(dist.js))
});
// Browserify
gulp.task('browserify', function() {
var b = browserify({
entries: src.jsApp,
debug: true,
// defining transforms here will avoid crashing your stream
transform: [vueify, debowerify, deamdify]
});
return b.bundle()
//Pass desired output filename to vinyl-source-stream
.pipe(source('bundle.js'))
// Start piping stream to tasks!
.pipe(gulp.dest(dist.js));
});
gulp.task('rescript', ['browserify'], function () {
browserSync.reload();
});
// Clean task
gulp.task('clean', function () {
return del('dist/**/*');
});
// Static server
gulp.task('serve', ['build', 'images', 'audio', 'video', 'fonts', 'favicon', 'scss', 'vendor', 'browserify'], function() {
browserSync.init({
server: "../../dist"
});
gulp.watch([src.scss, src.scssExternal], ['scss']);
gulp.watch(src.js, ['rescript']);
gulp.watch(src.img, ['images']);
gulp.watch([src.partials, src.html], ['rebuild']);
});
// Default task
gulp.task('default', ['serve']);