This repository has been archived by the owner on May 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
102 lines (89 loc) · 2.92 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
const gulp = require('gulp')
const autoprefixer = require('gulp-autoprefixer')
const babel = require('gulp-babel')
const cleancss = require('gulp-clean-css')
const gulpif = require('gulp-if')
const plumber = require('gulp-plumber')
const sass = require('gulp-sass')
const sassLint = require('gulp-sass-lint')
const sourcemaps = require('gulp-sourcemaps')
const svgstore = require('gulp-svgstore')
const svgmin = require('gulp-svgmin')
const uglify = require('gulp-uglify')
const runSequence = require('run-sequence')
const browserSync = require('browser-sync')
const argv = require('yargs').argv
let folder = './'
let dist = './dist'
let scss = `${folder}/src/scss/**/*.scss`
gulp.task('browser-sync', () => {
browserSync({
server: {
baseDir: folder
},
notify: false
})
})
gulp.task('bs-reload', () => browserSync.reload())
gulp.task('styles', () => {
return gulp.src(scss)
.pipe(sassLint())
.pipe(sassLint.format())
.pipe(sassLint.failOnError())
.pipe(plumber({
errorHandler: function(err) {
console.log(err.message)
this.emit('end')
}}))
.pipe(gulpif(!argv.minify, sourcemaps.init()))
.pipe(sass())
.pipe(gulpif(argv.minify, autoprefixer('last 1 versions')))
.pipe(gulpif(argv.minify, cleancss()))
.pipe(gulpif(!argv.minify, sourcemaps.write('./map')))
.pipe(gulp.dest(`${folder}/css`))
.pipe(browserSync.reload({stream: true}))
})
gulp.task('styleslint', () => {
return gulp.src(scss)
.pipe(sassLint())
.pipe(sassLint.format())
.pipe(sassLint.failOnError())
})
gulp.task('scripts', () => {
return gulp.src(`${folder}/src/js/**/*.js`)
.pipe(plumber({
errorHandler: function(err) {
console.log(err.message)
this.emit('end')
}}))
.pipe(gulpif(!argv.minify, sourcemaps.init()))
.pipe(babel())
.pipe(gulpif(argv.minify, uglify()))
.pipe(gulpif(!argv.minify, sourcemaps.write('./map')))
.pipe(gulp.dest(`${folder}/js/common`))
.pipe(browserSync.reload({stream: true}))
})
gulp.task('svgmin', () => {
return gulp.src(`${folder}/src/svg-symbols/*.svg`)
.pipe(svgmin())
.pipe(gulp.dest(`${folder}/trash/svg-store`))
})
gulp.task('svg', ['svgmin'], () => {
return gulp.src(`${folder}/trash/svg-store/*.svg`)
.pipe(svgstore({inlineSvg: true}))
.pipe(gulp.dest(`${folder}/img`))
})
gulp.task('default', ['styles', 'scripts', 'svg'])
gulp.task('dev', () => {
runSequence(['default'], 'browser-sync', () => {
gulp.watch(`${folder}/src/scss/**/*.scss`, ['styles'])
gulp.watch(`${folder}/src/js/**/*.js`, ['scripts'])
gulp.watch(`${folder}/**/*.html`, ['bs-reload'])
})
})
gulp.task('build', ['default'], () => {
gulp.src(`${folder}/css/**/*.css`, { base: '.' }).pipe(gulp.dest(dist))
gulp.src(`${folder}/js/**/*.js`, { base: '.' }).pipe(gulp.dest(dist))
gulp.src(`${folder}/img/**/*`, { base: '.' }).pipe(gulp.dest(dist))
gulp.src(`${folder}/*.html`).pipe(gulp.dest(dist))
})