forked from Candinya/Kratos-Rebirth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
82 lines (74 loc) · 2.33 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
const { src, dest, parallel, watch } = require('gulp');
const sass = require('gulp-dart-sass');
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
const postcss = require('gulp-postcss');
const terser = require('gulp-terser');
const rename = require('gulp-rename');
const babel = require("gulp-babel");
const sourcemaps = require('gulp-sourcemaps');
const browserSync = require('browser-sync').create();
sass.compiler = require('sass');
const configs = {
autoprefixer: {},
cssnano: {},
terser: {
output: {
comments: /^!/
},
ie8: true,
safari10: true
}
};
function buildSass(cb) {
src('src/scss/*.scss')
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(postcss([
autoprefixer(configs.autoprefixer),
cssnano(configs.cssnano)
]))
.pipe(rename({ suffix: '.min' }))
.pipe(sourcemaps.write('../maps'))
.pipe(dest('source/css'))
.pipe(browserSync.reload({stream: true}));
cb();
}
function buildHighlight(cb) {
src('src/scss/highlight/theme/*.scss')
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(postcss([
autoprefixer(configs.autoprefixer),
cssnano(configs.cssnano)
]))
.pipe(rename({ suffix: '.min' }))
.pipe(sourcemaps.write('../../maps'))
.pipe(dest('source/css/highlight'))
.pipe(browserSync.reload({stream: true}));
cb();
}
function minifyJs(cb) {
src('src/js/*.js')
.pipe(sourcemaps.init())
.pipe(babel({
presets: ["@babel/preset-env"]
}))
.pipe(terser(configs.terser))
.pipe(rename({ suffix: '.min' }))
.pipe(sourcemaps.write('../maps'))
.pipe(dest('source/js'))
.pipe(browserSync.reload({stream: true}));
cb();
}
const build = parallel(buildSass, minifyJs, buildHighlight);
function build_watch(cb) {
browserSync.init({
proxy: 'http://127.0.0.1:4000/'
});
watch('src/scss/**/*.scss', buildSass).on('change', browserSync.reload);
watch('src/js/*.js', minifyJs).on('change', browserSync.reload);
}
exports.default = build;
exports.build = build;
exports.watch = build_watch;