-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
131 lines (107 loc) · 3.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
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
131
var gulp = require('gulp'),
browserify = require('browserify'),
watchify = require('watchify'),
del = require('del'),
buffer = require('vinyl-buffer'),
source = require('vinyl-source-stream'),
objectAssign = require('object-assign');
// Load plugins
var $ = require('gulp-load-plugins')();
var VENDOR_STYLES = [
'node_modules/reveal.js/css/reveal.css',
'node_modules/highlight.js/styles/zenburn.css'
];
// Build a Browserify bundle and save to specified script under dist/
function bundleTo(bundler, fileName) {
return bundler
.bundle()
.pipe(source(fileName))
.pipe(buffer())
.pipe(gulp.dest('dist/scripts'))
.pipe($.connect.reload());
}
function getAppBuilder(opts) {
var opts = opts || {};
// https://github.com/gulpjs/gulp/blob/master/docs/recipes/fast-browserify-builds-with-watchify.md
return function() {
var browserifyOpts = {
entries: ['./src/index.js'],
debug: true
};
if (opts.watchify) {
browserifyOpts = objectAssign(watchify.args, browserifyOpts);
}
var bundler = browserify(browserifyOpts);
if (opts.watchify) bundler = watchify(bundler);
function rebundle() {
return bundleTo(bundler, 'bundle.js');
}
if (opts.watchify) {
bundler.on('update', rebundle);
}
return rebundle();
};
}
gulp.task('clean', function(cb) {
return del(['dist/**'], cb);
});
gulp.task('html', function() {
return gulp.src('src/index.html')
.pipe($.fileInclude({ basepath: './src/' }))
.pipe(gulp.dest('dist'))
.pipe($.connect.reload());
});
gulp.task('assets', function() {
return gulp.src('src/assets/**/*')
.pipe(gulp.dest('dist/assets'))
.pipe($.connect.reload());
});
gulp.task('styles:vendor', function() {
return gulp.src(VENDOR_STYLES)
.pipe($.sourcemaps.init())
.pipe($.concat('vendor.css'))
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('dist/styles'))
.pipe($.connect.reload());
});
gulp.task('styles:main', function() {
return gulp.src('src/styles/main.scss')
.pipe($.sourcemaps.init())
.pipe($.sass({
outputStyle: 'nested',
precision: 10,
includePaths: ['node_modules']
}))
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('dist/styles'))
.pipe($.connect.reload());
});
gulp.task('plugin:notes', function() {
return gulp.src('node_modules/reveal.js/plugin/notes/*')
.pipe(gulp.dest('dist/plugin/notes'));
});
gulp.task('scripts', getAppBuilder());
gulp.task('scripts:watchify', getAppBuilder({ watchify: true }));
gulp.task('build:noscripts', [
'html',
'assets',
'styles:vendor',
'styles:main',
'plugin:notes'
]);
gulp.task('build', ['build:noscripts', 'scripts']);
gulp.task('connect', function() {
$.connect.server({
root: 'dist',
port: 7777,
livereload: true
});
});
gulp.task('watch', ['build:noscripts', 'connect', 'scripts:watchify'], function() {
gulp.watch('src/**/*.html', ['html']);
gulp.watch('src/assets/**/*', ['assets']);
gulp.watch('src/styles/**/*.scss', ['styles:main']);
});
gulp.task('default', ['clean'], function() {
gulp.start('build');
});