forked from kolibri753/memory-card-game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
157 lines (146 loc) · 3.71 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
// Packages import
const gulp = require('gulp')
const less = require('gulp-less')
const stylus = require('gulp-stylus')
const sass = require('gulp-sass')(require('sass'))
const rename = require('gulp-rename')
const cleanCSS = require('gulp-clean-css')
const ts = require('gulp-typescript')
//const coffee = require('gulp-coffee')
const babel = require('gulp-babel')
const uglify = require('gulp-uglify')
const concat = require('gulp-concat')
const sourcemaps = require('gulp-sourcemaps')
const autoprefixer = require('gulp-autoprefixer')
const imagemin = require('gulp-imagemin')
const htmlmin = require('gulp-htmlmin')
const size = require('gulp-size')
//const gulppug = require('gulp-pug')
const newer = require('gulp-newer')
const browsersync = require('browser-sync').create()
const del = require('del')
// Paths of source files src and paths to resulting files dest
const paths = {
html: {
src: ['src/*.html', 'src/*.pug'],
dest: 'dist/'
},
styles: {
src: ['src/styles/**/*.sass', 'src/styles/**/*.scss', 'src/styles/**/*.styl', 'src/styles/**/*.less', 'src/styles/**/*.css'],
dest: 'dist/css/'
},
scripts: {
src: ['src/scripts/**/*.coffee', 'src/scripts/**/*.ts', 'src/scripts/**/*.js'],
dest: 'dist/js/'
},
images: {
src: 'src/img/**',
dest: 'dist/img/'
},
fonts: {
src: 'src/font/**',
dest: 'dist/font/'
}
}
// Empty dist directory, remove everything except images
function clean() {
return del(['dist/*'])
}
// Html and pug processing
function html() {
return gulp.src(paths.html.src)
//.pipe(gulppug())
.pipe(htmlmin({ collapseWhitespace: true }))
.pipe(size({
showFiles:true
}))
.pipe(gulp.dest(paths.html.dest))
.pipe(browsersync.stream())
}
// Handling Style Preprocessors
function styles() {
return gulp.src(paths.styles.src)
.pipe(sourcemaps.init())
//.pipe(less())
//.pipe(stylus())
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
cascade: false
}))
.pipe(cleanCSS({
level: 2
}))
.pipe(rename({
basename: 'style',
suffix: '.min'
}))
.pipe(sourcemaps.write('.'))
.pipe(size({
showFiles:true
}))
.pipe(gulp.dest(paths.styles.dest))
.pipe(browsersync.stream())
}
// Handling Javascript, Typescript and Coffeescript
function scripts() {
return gulp.src(paths.scripts.src)
.pipe(sourcemaps.init())
//.pipe(coffee({bare: true}))
/*
.pipe(ts({
noImplicitAny: true,
outFile: 'main.min.js'
}))
*/
.pipe(babel({
presets: ['@babel/env']
}))
.pipe(uglify())
.pipe(concat('main.min.js'))
.pipe(sourcemaps.write('.'))
.pipe(size({
showFiles:true
}))
.pipe(gulp.dest(paths.scripts.dest))
.pipe(browsersync.stream())
}
// Image Compression
function img() {
return gulp.src(paths.images.src)
.pipe(newer(paths.images.dest))
.pipe(imagemin({
progressive: true
}))
.pipe(size({
showFiles:true
}))
.pipe(gulp.dest(paths.images.dest))
}
function font() {
return gulp.src(paths.fonts.src)
.pipe(gulp.dest(paths.fonts.dest))
}
// Track changes in files and launch a live server
function watch() {
browsersync.init({
server: {
baseDir: "./dist"
}
})
gulp.watch(paths.html.dest).on('change', browsersync.reload)
gulp.watch(paths.html.src, html)
gulp.watch(paths.styles.src, styles)
gulp.watch(paths.scripts.src, scripts)
gulp.watch(paths.images.src, img)
gulp.watch(paths.fonts.src, font)
}
// Tasks for manually running gulp clean, gulp html, etc.
exports.clean = clean
exports.html = html
exports.styles = styles
exports.scripts = scripts
exports.img = img
exports.font = font
exports.watch = watch
// The task that is executed by the gulp command
exports.default = gulp.series(clean, html, gulp.parallel(styles, scripts, img, font), watch)