-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathgulpfile.js
101 lines (80 loc) · 2.24 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
// ----- Imports and variables ------
const { src, dest, watch, series, parallel, lastRun } = require('gulp');
const gulpLoadPlugins = require('gulp-load-plugins');
const $ = gulpLoadPlugins();
const browserSync = require('browser-sync');
const server = browserSync.create();
const del = require('del');
const autoprefixer = require('autoprefixer');
const paths = {
src: 'src',
dest: 'docs',
tmp: '.tmp'
};
// ----- Tasks ------
function styles() {
return src(`${paths.src}/styles/*.scss`)
.pipe($.plumber())
// .pipe($.sourcemaps.init())
.pipe($.sass.sync({
outputStyle: 'expanded',
precision: 10,
includePaths: ['.']
})
.on('error', $.sass.logError))
.pipe($.postcss([
autoprefixer()
]))
// .pipe($.sourcemaps.write())
// .pipe(dest(`${paths.tmp}/styles`))
.pipe(dest(`${paths.src}/styles`))
.pipe(server.reload({stream: true}));
};
exports.styles = styles;
function scripts() {
return src(`${paths.src}/scripts/direction-reveal.js`)
.pipe($.plumber())
.pipe($.babel({
plugins: ['@babel/plugin-transform-modules-umd']
}))
.pipe($.rename('direction-reveal-umd.js'))
.pipe(dest(`${paths.src}/scripts/`))
};
exports.scripts = scripts;
// ----- Serve tasks ------
function startAppServer() {
server.init({
port: 9000,
notify: false,
ghostMode: false,
server: {
// baseDir: [`${paths.tmp}`, `${paths.src}`],
baseDir: [`${paths.src}`],
routes: {
'/node_modules': 'node_modules'
},
serveStaticOptions: {
extensions: ['html']
}
}
});
watch([`${paths.src}/*.html`, `${paths.src}/**/*.js`]).on('change', server.reload);
watch(`${paths.src}/**/*.scss`, styles);
}
const compile = series(clean, parallel(styles, scripts));
exports.compile = compile;
let serve = series(compile, startAppServer);
exports.serve = serve;
// ----- Build tasks ------
function moveFiles() {
return src([`${paths.src}/**/*.{html,css,js,jpg,gif,png,webp,mp4,webm}`])
.pipe(dest(`${paths.dest}`));
};
exports.moveFiles = moveFiles;
function clean() {
return del([`${paths.tmp}`, `${paths.dest}`])
}
exports.clean = clean;
const build = series(compile, moveFiles);
exports.build = build;
exports.default = build;