-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
69 lines (60 loc) · 1.92 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
'use strict';
var gulp = require('gulp');
var sass = require('gulp-sass');
var pug = require("gulp-pug");
var cssnano = require('gulp-cssnano');
var rename = require('gulp-rename');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');
/* Local server */
var browserSync = require("browser-sync").create();
// Build SASS into CSS
gulp.task("build:sass", function() {
return gulp
.src(["src/style.scss", "src/challenge/**/*.scss"])
.pipe(sourcemaps.init())
.pipe(sass().on("error", sass.logError))
.pipe(autoprefixer())
.pipe(rename({ suffix: ".min" }))
.pipe(cssnano())
.pipe(sourcemaps.write("."))
.pipe(gulp.dest("dist"))
.pipe(browserSync.stream());
});
// Build PUG into HTML
gulp.task("build:pug", function() {
return gulp
.src(["src/index.pug", "src/challenge/**/*.pug"])
.pipe(pug())
.pipe(gulp.dest("dist"))
.pipe(browserSync.stream());
});
// Get JS modules from node_modules and concatenate in one file
gulp.task("build:js", function() {
return gulp
.src([
"node_modules/prismjs/prism.js",
"src/script.js"
])
.pipe(concat("script.js"))
.pipe(rename({ suffix: ".min" }))
.pipe(uglify())
.pipe(gulp.dest("dist"));
});
// Static server
gulp.task("serve", ["build:sass", "build:pug"], function() {
browserSync.init({
server: {
baseDir: "./dist",
serveStaticOptions: {
extensions: ["html"]
}
}
});
gulp.watch(['./src/challenge/**/*.scss', './src/style.scss'], ["build:sass"]);
gulp.watch(['./src/challenge/**/*.pug', './src/challenge/**/*.js', './src/index.pug'], ["build:pug"]);
});
gulp.task("build", ["build:sass", "build:pug"]);
gulp.task("default", ["serve"]);