-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
90 lines (79 loc) · 1.79 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
const gulp = require("gulp");
const webpack = require("webpack");
const sass = require("gulp-sass");
const rename = require("gulp-rename");
const postcss = require("gulp-postcss");
const imagemin = require('gulp-imagemin');
const autoprefixer = require("autoprefixer");
const cssnano = require("cssnano");
const del = require("del");
sass.compiler = require("node-sass");
const paths = {
sass: {
src: "./src/scss/**/*.scss",
dest: "./src/css/"
},
styles: {
src: "./src/css/*.css",
dest: "./assets/css"
},
images: {
src: "./src/img/**",
dest: "./assets/img"
},
scripts: {
src: "./src/js/**"
}
};
function clean() {
return del(["assets"]);
}
function buildCss() {
return gulp
.src(paths.sass.src)
.pipe(sass().on("error", sass.logError))
.pipe(gulp.dest(paths.sass.dest));
}
function postCss() {
var plugins = [
autoprefixer({
browsers: ["last 1 version", "> 1%", "not dead"],
grid: "autoplace"
}),
cssnano()
];
return gulp
.src(paths.styles.src)
.pipe(postcss(plugins))
.pipe(
rename({
basename: "main",
suffix: ".min"
})
)
.pipe(gulp.dest(paths.styles.dest));
}
function images() {
return gulp.src(paths.images.src)
.pipe(imagemin())
.pipe(gulp.dest(paths.images.dest))
}
function scripts(cb) {
return webpack(require("./webpack.config"), () => {
cb();
});
}
function watch() {
gulp.watch(paths.scripts.src, scripts);
gulp.watch(paths.sass.src, buildCss);
gulp.watch(paths.styles.src, postCss);
}
const build = gulp.series(clean, buildCss, postCss, images, scripts);
exports.clean = clean;
exports.sass = buildCss;
exports.css = postCss;
exports.scripts = scripts;
exports.watch = watch;
exports.build = build;
exports.images = images;
exports.default = build;