-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
144 lines (124 loc) · 3.25 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
132
133
134
135
136
137
138
139
140
141
142
143
144
// common
const gulp = require("gulp");
const plumber = require("gulp-plumber");
const gulpIf = require("gulp-if");
// clear task
const del = require("del");
// pug task
const pug = require("gulp-pug");
// scss task
const sass = require("gulp-sass");
const autoprefixer = require("gulp-autoprefixer");
const sourcemaps = require("gulp-sourcemaps");
const minifyCss = require("gulp-clean-css");
//js
const webpack = require("webpack");
const gulpWebpack = require("webpack-stream");
const webpackConfig = require("./webpack.config.js");
//images
const imagemin = require("gulp-imagemin");
// server
const browserSync = require("browser-sync").create();
//svg-sprite
const svgSprite = require("gulp-svg-sprite");
const svgmin = require("gulp-svgmin");
const isProduction = process.env.NODE_ENV === "production";
const PATHS = {
app: "./app",
dist: "./dist"
};
gulp.task("clear", () => del(PATHS.dist));
gulp.task("templates", () => {
return gulp
.src(`${PATHS.app}/pages/**/*.pug`)
.pipe(plumber())
.pipe(pug({ pretty: true }))
.pipe(gulp.dest(PATHS.dist));
});
gulp.task("styles", () => {
return gulp
.src(`${PATHS.app}/common/styles/app.scss`)
.pipe(plumber())
.pipe(gulpIf(!isProduction, sourcemaps.init()))
.pipe(sass())
.pipe(autoprefixer())
.pipe(gulpIf(isProduction, minifyCss()))
.pipe(gulpIf(!isProduction, sourcemaps.write()))
.pipe(gulp.dest(`${PATHS.dist}/assets/styles`));
});
gulp.task("scripts", () => {
return gulp
.src(`${PATHS.app}/common/scripts/*.js`, { since: gulp.lastRun("scripts") })
.pipe(plumber())
.pipe(gulpWebpack(webpackConfig, webpack))
.pipe(gulp.dest(`${PATHS.dist}/assets/scripts`));
});
gulp.task("images", () => {
return gulp
.src(`${PATHS.app}/common/images/**/*.+(png|jpg|jpeg|gif|svg|ico)`)
.pipe(plumber())
.pipe(gulpIf(isProduction, imagemin()))
.pipe(gulp.dest(`${PATHS.dist}/assets/images`));
});
gulp.task("copy", () => {
return gulp
.src(`${PATHS.app}/common/fonts/**/*`)
.pipe(plumber())
.pipe(gulp.dest(`${PATHS.dist}/assets/fonts`));
});
gulp.task("icons", () => {
return gulp
.src(`${PATHS.app}/common/icons/**/*.svg`)
.pipe(plumber())
.pipe(svgmin({
js2svg: {
pretty: true
}
}))
.pipe(
svgSprite({
mode: {
symbol: {
sprite: "../dist/assets/images/icons/sprite.svg",
render: {
scss: {
dest:'../app/common/styles/helpers/sprites.scss',
template: './app/common/styles/helpers/sprite-template.scss'
}
}
}
}
})
)
.pipe(gulp.dest('./'));
});
gulp.task("server", () => {
browserSync.init({
server: PATHS.dist
});
browserSync.watch(PATHS.dist + "/**/*.*").on("change", browserSync.reload);
});
gulp.task("watch", () => {
gulp.watch(`${PATHS.app}/**/*.pug`, gulp.series("templates"));
gulp.watch(`${PATHS.app}/**/*.scss`, gulp.series("styles"));
gulp.watch(`${PATHS.app}/**/*.js`, gulp.series("scripts"));
gulp.watch(
`${PATHS.app}/common/images/**/*.+(png|jpg|jpeg|gif|svg|ico)`,
gulp.series("images")
);
});
gulp.task(
"default",
gulp.series(
"icons",
gulp.parallel("templates", "styles", "scripts", "images", "copy"),
gulp.parallel("watch", "server")
)
);
gulp.task(
"production",
gulp.series(
"clear",
gulp.parallel("templates", "icons", "styles", "scripts", "images", "copy")
)
);