-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
132 lines (114 loc) · 3.29 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
const { src, dest, task, series, watch, parallel } = require("gulp");
const {SRC_PATH, DIST_PATH, STYLE_LIBS, JS_LIBS} = require('./gulp.config');
const env = process.env.NODE_ENV;
const gulpif = require('gulp-if');
const ghPages = require('gulp-gh-pages')
const sass = require('gulp-sass');
const cleanCSS = require('gulp-clean-css');
const sassGlob = require('gulp-sass-glob');
const px2rem = require('gulp-smile-px2rem');
const autoprefixer = require('gulp-autoprefixer');
const gcmq = require('gulp-group-css-media-queries');
const svgo = require('gulp-svgo');
const svgSprite = require('gulp-svg-sprite');
const babel = require('gulp-babel');
const uglify = require('gulp-uglify');
const concat = require('gulp-concat');
const cleanDist = require('gulp-clean');
const sourcemaps = require('gulp-sourcemaps');
const browserSync = require('browser-sync').create();
const reload = browserSync.reload;
sass.compiler = require('node-sass');
const removedFiles = [
`${DIST_PATH}/*.js`,
`${DIST_PATH}/*.css`,
`${DIST_PATH}/*.html`
]
task('clean', () => {
return src( removedFiles, { read: false })
.pipe(cleanDist());
})
task('copy:html', () => {
return src(`${SRC_PATH}/*.html`)
.pipe(dest(DIST_PATH))
.pipe(reload({ stream: true }));
})
task('styles', function () {
return src([...STYLE_LIBS, `${SRC_PATH}/scss/main.scss`])
.pipe(gulpif(env === 'dev', sourcemaps.init()))
.pipe(concat("main.min.scss"))
.pipe(sassGlob())
.pipe(sass().on('error', sass.logError))
// .pipe(px2rem())
.pipe(gulpif(env === 'prod', autoprefixer({
browsers: ['last 2 versions'],
cascade: false
})))
.pipe(gulpif(env === 'prod', gcmq()))
.pipe(gulpif(env === 'prod', cleanCSS()))
.pipe(gulpif(env === 'dev', sourcemaps.write()))
.pipe(dest(DIST_PATH))
.pipe(reload({ stream: true }));
});
task('scripts', () => {
return src([...JS_LIBS, `${SRC_PATH}/scripts/*.js`])
.pipe(gulpif(env === 'dev', sourcemaps.init()))
.pipe(concat('main.min.js', {newLine: ';'}))
.pipe(gulpif(env === 'prod', babel({
presets: ['@babel/env']
})))
.pipe(gulpif(env === 'prod', uglify()))
.pipe(gulpif(env === 'dev', sourcemaps.write()))
.pipe(dest(DIST_PATH))
.pipe(reload({ stream: true }));
});
task('icons', () => {
return src(`${SRC_PATH}/images/icons/*.svg`)
.pipe(svgo({
plugins: [
{
removeAttrs: {
attrs: '(fill|stroke|style|width|height|data.*)'
}
}
]
}))
.pipe(svgSprite({
mode: {
symbol: {
sprite: '../sprite.svg'
}
}
}))
.pipe(dest(`${DIST_PATH}/images/icons`));
});
task('server', () => {
browserSync.init({
server: {
baseDir: `./${DIST_PATH}`
},
open: false
});
});
task('pages', () => {
return src("./dist/**/*")
.pipe(ghPages())
})
task('watch', () => {
watch(`./${SRC_PATH}/scss/**/*.scss`, series('styles'));
watch(`./${SRC_PATH}/*.html`, series('copy:html'));
watch(`./${SRC_PATH}/scripts/*.js`, series('scripts'));
// watch(`./${SRC_PATH}/images/icons/*.svg`, series('icons'));
});
task('default',
series('clean',
parallel('copy:html', 'styles', 'scripts'),
parallel('watch', 'server')
)
);
task('build',
series(
'clean',
parallel('copy:html', 'styles', 'scripts')
)
);