-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
119 lines (111 loc) · 3.07 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
const gulp = require("gulp");
const postcss = require("gulp-postcss");
const atImport = require("postcss-import");
const mqpacker = require("css-mqpacker");
const cssnano = require("cssnano");
// const cssimport = require("gulp-cssimport");
const autoprefixer = require("gulp-autoprefixer");
const sourcemaps = require("gulp-sourcemaps");
const sass = require("gulp-sass")(require("sass"));
const rename = require("gulp-rename");
const browserSync = require("browser-sync").create();
const styleWatch = "src/*.css";
// const cssAssetWatch = "assets/css/style.css";
const sassWatch = "sass/**/*.scss";
const webFonts = "assets/css/webfonts/all.css";
const eslint = require("gulp-eslint");
function style() {
const processors = [
atImport,
mqpacker,
cssnano({
calc: { precision: 2 },
}),
];
return gulp
.src("src/style.css")
.pipe(sourcemaps.init())
.pipe(autoprefixer())
.pipe(postcss(processors))
.pipe(gulp.dest("./"))
.pipe(sourcemaps.write("./"))
.pipe(browserSync.stream());
}
/* function import_styles(done){
gulp.src("assets/css/style.css")
.pipe( sourcemaps.init() )
.pipe(cssimport([]))
.pipe( sourcemaps.write("./") )
.pipe(gulp.dest("./"));
done();
} */
function compileSass(done) {
gulp
.src("sass/*.scss")
.pipe(sourcemaps.init())
.pipe(sass().on("error", sass.logError))
.pipe(sourcemaps.write("./"))
.pipe(gulp.dest("./css"))
.pipe(browserSync.stream());
done();
}
function processFonts() {
const processors = [
atImport,
mqpacker,
cssnano({
calc: { precision: 2 },
}),
];
return gulp
.src("assets/css/webfonts/all.css")
.pipe(sourcemaps.init())
.pipe(autoprefixer())
.pipe(postcss(processors))
.pipe(
rename({
suffix: ".min",
})
)
.pipe(sourcemaps.write("./"))
.pipe(
gulp.dest(function (file) {
return file.base;
})
)
.pipe(browserSync.stream());
}
function watchFiles() {
gulp.watch(styleWatch, style);
// gulp.watch( cssAssetWatch , import_styles );
gulp.watch(sassWatch, compileSass);
gulp.watch(webFonts, processFonts);
gulp.watch("scripts/*.js", lintJS);
browserSync.init({
proxy: "http://dev.local/",
});
}
function lintJS(done) {
gulp
.src(["scripts/js-main.js"])
// eslint() attaches the lint output to the "eslint" property
// of the file object so it can be used by other modules.
.pipe(eslint())
// eslint.format() outputs the lint results to the console.
// Alternatively use eslint.formatEach() (see Docs).
.pipe(eslint.format())
// To have the process exit with an error code (1) on
// lint error, return the stream and pipe to failAfterError last.
.pipe(eslint.failAfterError())
.on("error", handleError);
done();
}
function handleError(err) {
// console.log(err.toString());
}
gulp.task("default", gulp.series(style, compileSass, processFonts, lintJS));
gulp.task("sass", compileSass);
gulp.task("webfonts", processFonts);
gulp.task("watch", watchFiles);
gulp.task("style", style);
gulp.task("lintjs", lintJS);