-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
76 lines (68 loc) · 1.75 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
const { src, dest, parallel, series, watch: gulpWatch } = require("gulp");
const autoprefixer = require("autoprefixer");
const babelify = require("babelify");
const browserify = require("browserify");
const cssnano = require("cssnano");
const del = require("del");
const cssimport = require("postcss-import");
const postcss = require("gulp-postcss");
const sass = require("gulp-sass");
const sourcemaps = require("gulp-sourcemaps");
const terser = require("gulp-terser");
const vinylSourceStream = require("vinyl-source-stream");
const vinylBuffer = require("vinyl-buffer");
sass.compiler = require("node-sass");
const clean = () => {
return del(["dist/**", "!dist"]);
};
const images = () => {
return src("src/images/**/*").pipe(dest("dist/images"));
};
const css = () => {
return src("src/css/main.scss")
.pipe(sourcemaps.init())
.pipe(sass().on("error", sass.logError))
.pipe(
postcss([
cssimport(),
autoprefixer({
grid: "autoplace",
}),
cssnano({
preset: [
"default",
{
calc: false,
},
],
}),
])
)
.pipe(sourcemaps.write("."))
.pipe(dest("dist/css"));
};
const js = () => {
return browserify({
entries: ["src/js/main.js"],
debug: false,
})
.transform(
babelify.configure({
presets: ["@babel/preset-env"],
})
)
.bundle()
.pipe(vinylSourceStream("main.js"))
.pipe(vinylBuffer())
.pipe(terser())
.pipe(dest("dist/js"));
};
const watch = () => {
gulpWatch("src/css", css);
gulpWatch("src/js", js);
gulpWatch("src/image", images);
};
exports.images = images;
exports.css = css;
exports.js = js;
exports.default = series(clean, parallel(css, js, images), watch);