-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
131 lines (113 loc) · 3.34 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
const gulp = require('gulp')
const log = require('fancy-log')
const source = require('vinyl-source-stream')
const babelify = require('babelify')
const watchify = require('watchify')
const exorcist = require('exorcist')
const browserify = require('browserify')
const browserSync = require('browser-sync').create()
const sass = require('gulp-sass')
const imagemin = require('gulp-imagemin')
const Hexo = require('hexo');
const runSequence = require('run-sequence');
const minify = require('gulp-minify');
const cleanCSS = require('gulp-clean-css');
const rename = require("gulp-rename");
const run = require('gulp-run-command').default;
gulp.task('generate', function(cb) {
/* generate html with 'hexo generate' */
var hexo = new Hexo(process.cwd(), {
config: `_config.yml`,
watch: false,
});
hexo.init().then(function() {
return hexo.call('generate');
}).then(function() {
return hexo.exit();
}).then(function() {
return cb()
}).catch(function(err) { console.log(err);
hexo.exit(err);
return cb(err);
})
})
var config = {
paths: {
src: {
scss: './themes/navy/source/scss/*.scss',
js: [
'./themes/navy/source/js/dev.js',
],
},
dist: {
css: './public/css',
js: './public/js'
}
}
}
// Watchify args contains necessary cache options to achieve fast incremental bundles.
// See watchify readme for details. Adding debug true for source-map generation.
watchify.args.debug = true
// Input file.
var bundler = watchify(browserify(config.paths.src.js, watchify.args))
// Babel transform
bundler.transform(
babelify.configure({
sourceMapRelative: './themes/navy/source/js/'
})
)
// On updates recompile
bundler.on('update', bundle)
function bundle() {
log('Compiling JS...')
return bundler
.bundle()
.on('error', function(err) {
log(err.message)
browserSync.notify('Browserify Error!')
this.emit('end')
})
.pipe(exorcist('./themes/navy/source/js/main.js.map'))
.pipe(source('main.js'))
.pipe(gulp.dest('./themes/navy/source/js'))
.pipe(browserSync.stream({ once: true }))
}
gulp.task('compress', ['sass'], function() {
gulp.src('./themes/navy/source/js/main.js')
.pipe(minify({
ext: {
min: '.min.js'
},
}))
.pipe(gulp.dest('./public/js/'))
gulp.src('./public/css/main.css')
.pipe(cleanCSS())
.pipe(rename("main.min.css"))
.pipe(gulp.dest('./public/css/'));
});
gulp.task('bundle', function() {
return bundle()
})
gulp.task('sass', function() {
return gulp.src("./themes/navy/source/scss/main.scss")
.pipe(sass())
.on('error', log)
.pipe(gulp.dest(config.paths.dist.css))
.pipe(browserSync.stream())
})
gulp.task('watch', function() {
gulp.watch(config.paths.src.scss, ['compress'])
});
gulp.task('run', function(cb) {
runSequence( 'generate', 'compress', 'bundle', 'watch')
});
gulp.task('exit', function(cb) {
process.exit(0);
});
gulp.task('build', function(cb) {
runSequence('generate', 'compress', 'bundle', 'exit')
});
gulp.task('run', function(cb) {
runSequence('generate', 'compress', 'bundle', 'watch')
});
gulp.task('default', [])