-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
60 lines (51 loc) · 1.61 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
const gulp = require('gulp');
const sass = require('gulp-sass');
const pug = require('gulp-pug');
const concat = require('gulp-concat');
const filter = require('gulp-filter');
const sourcemaps = require('gulp-sourcemaps');
const uglify = require('gulp-uglify');
const browserSync = require('browser-sync').create();
const story = require('./story_transformer');
const outFolder = 'docs';
const srcFolder = 'src';
gulp.task('template', () => {
return gulp.src(`${srcFolder}/templates/*.pug`)
.pipe(pug({
filters: { 'story': story.render },
}))
.pipe(gulp.dest(outFolder));
});
gulp.task('scss', () => {
return gulp.src(`${srcFolder}/scss/app.scss`)
.pipe(sourcemaps.init())
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(sourcemaps.write())
.pipe(gulp.dest(outFolder))
.pipe(filter('**/*.css'))
.pipe(browserSync.stream())
});
gulp.task('js', () => {
return gulp.src(`${srcFolder}/js/*.js`)
.pipe(concat('app.js'))
.pipe(uglify()).on('error', (err) => console.log(err))
.pipe(gulp.dest(outFolder));
});
gulp.task('js-watch', ['js'], (done) => {
browserSync.reload();
done();
});
gulp.task('build', ['template', 'scss', 'js']);
// Build is a pre-req so that we start serving the latest version of files
gulp.task('serve', ['build'], () => {
// Start the browser sync server
browserSync.init({
server: {
baseDir: 'docs',
},
});
// Watch for changes to SCSS files and trigger the build process when
// they are updated
gulp.watch(`${srcFolder}/scss/**/*.scss`, ['scss']);
gulp.watch(`${srcFolder}/js/*.js`, ['js-watch']);
});