-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
169 lines (151 loc) · 4.67 KB
/
gulpfile.babel.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
/**
* Gulp default configuration for chrome extension.
* @license MIT
* @author Evens Pierre <[email protected]>
*/
const zip = require('gulp-zip')
const sass = require('gulp-sass')
const cache = require('gulp-cache')
const babel = require('gulp-babel')
const clean = require('gulp-clean')
const eslint = require('gulp-eslint')
const rename = require('gulp-rename')
const uglify = require('gulp-uglify')
const minify = require('gulp-minifier')
const imagemin = require('gulp-imagemin')
const cleanCSS = require('gulp-clean-css')
const jsonmin = require('gulp-json-minify')
const rollup = require('gulp-better-rollup')
const sourcemaps = require('gulp-sourcemaps')
const commonjs = require('@rollup/plugin-commonjs')
const resolve = require('@rollup/plugin-node-resolve')
const { src, dest, watch, series, parallel } = require('gulp')
function cssTranspile () {
return src('src/scss/**/*.scss')
.pipe(sass())
.pipe(dest('tmp/styles'))
}
function cssMinify () {
return src('tmp/styles/**/*.css')
.pipe(sourcemaps.init())
.pipe(cleanCSS({ compatibility: '*' }))
.pipe(rename({ suffix: '.min' }))
.pipe(sourcemaps.write())
.pipe(dest('dist/css'))
}
function cssVendor () {
return src([
'node_modules/codemirror/lib/codemirror.css',
'node_modules/simplemde/dist/simplemde.min.css',
'node_modules/simplebar/dist/simplebar.min.css',
'node_modules/bootstrap/dist/css/bootstrap.min.css',
'node_modules/@fortawesome/fontawesome-free/css/all.min.css'
])
.pipe(dest('dist/vendor/css'))
}
function fontVendor () {
return src([
'node_modules/@fortawesome/fontawesome-free/webfonts/*'
])
.pipe(dest('dist/vendor/webfonts'))
}
function jsTranspile () {
return src('src/js/**/*.js')
.pipe(sourcemaps.init())
.pipe(babel({ presets: ['@babel/env'] }))
.pipe(sourcemaps.write())
.pipe(dest('tmp/js'))
}
function jsRollup () {
return src('tmp/js/**/*.js')
.pipe(rollup({ plugins: [resolve(), commonjs()] }, 'umd'))
.pipe(dest('tmp/js'))
}
function jsMinify () {
return src('tmp/js/*.js')
.pipe(rename({ suffix: '.min' }))
// .pipe(uglify())
.pipe(dest('dist/js'))
}
function jsVendor () {
return src([
'node_modules/vue/dist/vue.min.js',
'node_modules/jquery/dist/jquery.min.js',
'node_modules/codemirror/lib/codemirror.js',
'node_modules/simplemde/dist/simplemde.min.js',
'node_modules/simplebar/dist/simplebar.min.js',
'node_modules/bootstrap/dist/js/bootstrap.min.js'
])
.pipe(dest('dist/vendor/js'))
}
function htmlMinify () {
return src('src/**/*.html')
.pipe(minify({
minify: true,
minifyHTML: {
minifyJS: true,
minifyCSS: true,
removeComments: true,
collapseWhitespace: true,
conservativeCollapse: true
}
}))
.pipe(dest('dist'))
}
function imageMinify () {
return src('src/img/**/*.+(png|jpg|gif|svg)')
.pipe(cache(imagemin({
interlaced: true,
progressive: true,
svgoPlugins: [{ cleanupIDs: false }]
})))
.pipe(dest('dist/img'))
}
function jsonMinify () {
return src('src/**/*.json')
.pipe(jsonmin())
.pipe(dest('dist'))
}
function jsLint () {
return src('src/js/**/*.js')
.pipe(eslint({
env: {
es6: true
}
}))
.pipe(eslint.format())
.pipe(eslint.failAfterError())
}
function zipFiles () {
return src('dist')
.pipe(zip('snippetify.zip'))
.pipe(dest('./'))
}
function removeZip () {
return src('snippetify.zip', { read: false, allowEmpty: true }).pipe(clean())
}
function cleanTmp () {
return src('tmp', { read: false, allowEmpty: true }).pipe(clean())
}
function cleanDist () {
return src('dist', { read: false, allowEmpty: true }).pipe(clean())
}
function watchFiles (cb) {
watch('src/**/*.json', series(jsonMinify))
watch('src/**/*.html', series(htmlMinify))
watch('src/js/**/*.js', series(jsLint, jsTranspile, jsRollup, jsMinify))
watch('src/scss/**/*.scss', series(cssTranspile, cssMinify))
watch('src/img/**/*.+(png|jpg|gif|svg)', series(imageMinify))
cb() // Async completion
}
exports.clean = parallel(cleanDist, cleanTmp, removeZip)
exports.watch = watchFiles
exports.default = series(
cleanDist,
parallel(jsLint, jsVendor, cssVendor, fontVendor),
parallel(jsTranspile, cssTranspile),
jsRollup,
parallel(cssMinify, jsMinify, htmlMinify, imageMinify, jsonMinify),
zipFiles,
cleanTmp
)