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