forked from Bahbv/AMPEr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
130 lines (117 loc) · 2.66 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
const gulp = require("gulp"),
browserSync = require("browser-sync").create(),
sass = require("gulp-sass"),
postcss = require("gulp-postcss"),
autoprefixer = require("autoprefixer"),
cssnano = require("cssnano"),
babel = require("gulp-babel"),
concat = require("gulp-concat");
/* Paths to be used */
const paths = {
styles: {
src: ["./src/scss/main.scss"],
all: ["./src/scss/*.scss","./src/scss/**/*.scss"],
dest: "./dist/css/"
},
scripts: {
src: ["./src/js/*.js"],
lib: "./src/js/lib/*.js",
dest: "./dist/js/"
},
html: {
src: ["./index.html"],
},
AMPEr: {
scss: ['./src/AMPEr/scss/AMPEr.scss'],
scss_dest: "./dist/AMPEr/css/",
js: ["./src/AMPEr/js/AMPEr.js"],
}
};
/* Process the styles */
function processStyles(done) {
return gulp.series(style, amperStyle, done => {
done();
})(done);
}
function style() {
return gulp
.src(paths.styles.src)
.pipe(sass())
.on("error", sass.logError)
.pipe(postcss([autoprefixer()]))
.pipe(gulp.dest(paths.styles.dest))
.pipe(browserSync.stream());
}
function amperStyle() {
return gulp
.src(paths.AMPEr.scss)
.pipe(sass())
.on("error", sass.logError)
.pipe(postcss([autoprefixer()]))
.pipe(gulp.dest(paths.AMPEr.scss_dest))
.pipe(browserSync.stream());
}
/* Process the scripts */
function processScripts(done) {
return gulp.series(
preprocessJs,
preprocessAmperJs,
concatJs,
reload,
done => {
done();
}
)(done);
}
function preprocessJs() {
return gulp
.src(paths.scripts.src)
.pipe(
babel({
presets: ["@babel/env"],
plugins: ["@babel/plugin-proposal-class-properties"]
})
)
.pipe(gulp.dest("./dist/js/build/"));
}
function preprocessAmperJs() {
return gulp
.src(paths.AMPEr.js)
.pipe(
babel({
presets: ["@babel/env"],
plugins: ["@babel/plugin-proposal-class-properties"]
})
)
.pipe(gulp.dest("./dist/AMPEr/js/"));
}
function concatJs() {
return gulp
.src([
paths.scripts.lib,
"./dist/js/build/*.js"
])
.pipe(concat("main-concat.js"))
.pipe(gulp.dest("./dist/js/"));
}
/* Tasks and browserSync */
function reload(done) {
browserSync.reload();
done();
}
function watch() {
browserSync.init({
server: {
baseDir: "./"
// if using vhost-based url
//proxy: "local.dev"
}
});
gulp.watch(paths.styles.all, processStyles);
gulp.watch(paths.AMPEr.scss, processStyles);
gulp.watch(paths.scripts.src, processScripts);
gulp.watch(paths.AMPEr.js, processScripts);
gulp.watch(paths.html.src, reload);
}
/* Our tasks */
gulp.task("default", watch);