-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
86 lines (76 loc) · 2.2 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
const gulp = require("gulp");
const sass = require("gulp-sass");
const rename = require("gulp-rename");
const cssmin = require("gulp-cssnano");
const prefix = require("gulp-autoprefixer");
const sourcemaps = require("gulp-sourcemaps");
const imagemin = require("gulp-imagemin");
// Essential files/directory for development mode source file
const inputPath = "src/assets/sass/*.scss";
const outputPath = "src/assets/css";
const cssUrl = "style.css";
const watcherResource = "src/assets/sass/**/*";
//Essential file/directory for production mode
const production_outputPath = "dist/assets/css";
const sassOptions = {
outputStyle: "expanded", //expanded,compressed
};
const prefixerOptions = {
cascade: false,
};
// copy all html file for production
gulp.task("html", function () {
return gulp.src("src/*.html").pipe(gulp.dest("dist"));
});
// copy all script file for production
gulp.task("script", function () {
return gulp.src("src/assets/js/**/*.js").pipe(gulp.dest("dist/assets/js"));
});
// copy all image file for production
gulp.task("images", function () {
return gulp
.src("src/assets/img/**/*")
.pipe(imagemin())
.pipe(gulp.dest("dist/assets/img"));
});
gulp.task("styles", function () {
return (
gulp
.src(inputPath)
// .pipe(sourcemaps.init())
.pipe(sass(sassOptions))
.pipe(prefix(prefixerOptions))
.pipe(rename(cssUrl))
.pipe(gulp.dest(outputPath))
.pipe(cssmin())
.pipe(rename({ suffix: ".min" }))
// .pipe(sourcemaps.write('.'))
.pipe(gulp.dest(outputPath))
);
});
gulp.task("production_styles", function () {
return gulp
.src(inputPath)
.pipe(sourcemaps.init())
.pipe(sass(sassOptions))
.pipe(prefix(prefixerOptions))
.pipe(rename(cssUrl))
.pipe(gulp.dest(production_outputPath))
.pipe(cssmin())
.pipe(rename({ suffix: ".min" }))
.pipe(sourcemaps.write("."))
.pipe(gulp.dest(production_outputPath));
});
// development mode
gulp.task(
"start",
gulp.series("styles", function (done) {
gulp.watch(watcherResource, gulp.parallel("styles"));
done();
})
);
//production mode
gulp.task(
"production",
gulp.series(gulp.parallel("html", "production_styles", "images", "script"))
);