-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
173 lines (173 loc) · 4.43 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
170
171
172
173
import { series, parallel, watch, src, dest } from 'gulp'
import autoprefixer from 'autoprefixer'
import babel from 'gulp-babel'
import browserSync from 'browser-sync'
import changed from 'gulp-changed'
import colors from 'colors'
import concat from 'gulp-concat'
import cssnano from 'cssnano'
import figlet from 'figlet'
import eslint from 'gulp-eslint'
import imagemin from 'gulp-imagemin'
import sassLint from 'gulp-sass-lint'
import lolcatjs from 'lolcatjs'
import minify from 'gulp-minify'
import packageJSON from './package.json'
import plumber from 'gulp-plumber'
import postcss from 'gulp-postcss'
import rename from 'gulp-rename'
import sass from 'gulp-sass'
import sourcemaps from 'gulp-sourcemaps'
const paths = {
src: {
sass: './src/sass/**/*.scss',
js: './src/js/**/*.js',
img: './src/img/**/*.*',
all: './src/**/**/*.*'
},
dest: {
css: './dist/css/',
js: './dist/js/',
img: './dist/img/',
}
}
colors.setTheme({
silly: ['rainbow', 'bold'],
verbose: ['cyan', 'bold'],
prompt: ['grey', 'bold'],
info: ['green', 'bold'],
warn: ['yellow', 'bold'],
debug: ['blue', 'bold'],
error: ['red', 'bold'],
})
lolcatjs.options.seed = Math.round(Math.random() * 1000)
lolcatjs.options.colors = true
function welcome(done) {
let starting = figlet.textSync('starting tasks...', {
font: 'speed',
horizontalLayout: 'default',
verticalLayout: 'default'
})
lolcatjs.fromString(`${starting}`);
done()
}
function sassCompile(done) {
return src(paths.src.sass)
.pipe(sassLint({
options: {
formatter: 'stylish',
'merge-default-rules': true
},
// all linting rules: https://github.com/sasstools/sass-lint/tree/master/docs/rules
rules: {
'single-line-per-selector': 0,
'no-css-comments': 0,
'indentation': { 'size': 'tab' },
'property-sort-order': 0,
'no-qualifying-elements': 0,
'force-attribute-nesting': 0,
'force-pseudo-nesting': 0,
'force-element-nesting': 0,
'no-vendor-prefixes': 0,
},
}))
.pipe(sassLint.format())
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'expanded',
indentType: 'tab',
indentWidth: 1,
}))
.pipe(dest(paths.dest.css))
.pipe(rename({extname: '.min.css'}))
.pipe(postcss([autoprefixer({
cascade: false
}), cssnano()]))
.pipe(sourcemaps.write('./'))
.pipe(dest(paths.dest.css))
.pipe(browserSync.stream())
done()
}
function jsCompile(done) {
return src(paths.src.js)
.pipe(eslint({
'parserOptions': {
'ecmaVersion': 6,
},
'extends': 'eslint:recommended',
'rules': {
'semi': ['warn', 'always'],
'no-console': 'off',
},
}))
.pipe(eslint.formatEach('pretty'))
.pipe(eslint.results(results => {
console.log(`JavaScript Warnings: `.prompt + `${results.warningCount}`.warn)
console.log(`JavaScript Errors: `.prompt + `${results.errorCount}`.error)
}))
.pipe(plumber())
.pipe(babel({
presets: ['@babel/env']
}))
.on('error', (err) => {
console.warn(`[JS Babel Error] ${err.message}`.error)
})
.pipe(concat('bundle.js'))
.pipe(sourcemaps.init())
.pipe(minify({
ext:{
min:'.min.js'
},
mangle: true,
}))
.pipe(sourcemaps.write('./'))
.pipe(dest(paths.dest.js))
.pipe(browserSync.stream())
done()
}
function imgCompress(done) {
return src(paths.src.img)
.pipe(plumber())
.pipe(changed(paths.dest.img))
.pipe(imagemin())
.pipe(dest(paths.dest.img))
.pipe(browserSync.stream())
done()
}
function reload() {
browserSync.reload()
}
function serve(done) {
browserSync.init({
server: {
baseDir: './'
},
})
done()
}
function watchFiles(done) {
watch([paths.src.sass], sassCompile)
watch([paths.src.js], jsCompile)
watch([paths.src.img], imgCompress)
watch([paths.src.all]).on('change', reload)
done()
}
function getStarted(done) {
lolcatjs.fromString(`You are working on ${packageJSON.name}, version: ${packageJSON.version}, by ${packageJSON.author}`);
let leggo = figlet.textSync('LETS GO!', {
font: 'Dancing Font',
horizontalLayout: 'full',
verticalLayout: 'full'
})
lolcatjs.fromString(`${leggo}`);
done()
}
const build = series(sassCompile, jsCompile, imgCompress)
const serveWatch = parallel(serve, watchFiles)
exports.default = series(
welcome,
build,
serveWatch,
getStarted,
)