This repository has been archived by the owner on Jan 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
110 lines (94 loc) · 2.84 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
/* jshint strict: false */
/* jshint node: true */
var autoprefixer = require('gulp-autoprefixer');
var browserify = require('browserify');
var babelify = require('babelify');
var browserSync = require('browser-sync').create();
var buffer = require('vinyl-buffer');
var del = require('del');
var envify = require('envify/custom');
var ghPages = require('gulp-gh-pages');
var gulp = require('gulp');
var path = require('path');
var riot = require('riotify');
var runSequence = require('run-sequence');
var sass = require('gulp-sass');
var source = require('vinyl-source-stream');
var sourcemaps = require('gulp-sourcemaps');
var watchify = require('watchify');
var $ = {
dist: "./dist/",
app: "./src/app.js",
html: "./src/**/*.html",
js: "./src/js/*.js",
scss: "./src/scss/**/*.scss",
tag: "./src/tag/*.tag",
env: "development"
};
function compile(watch) {
var bundler = watchify(browserify($.app), {debug: true})
.transform(envify({NODE_ENV: $.env}))
.transform(babelify)
.transform(riot, {type: 'es6'});
function rebundle() {
bundler.bundle()
.on('error', function(err) { console.error(err); this.emit('end'); })
.pipe(source(path.basename($.app)))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write())
.pipe(gulp.dest($.dist));
}
if (watch) {
bundler.on('update', function() {
console.log('-> bundling...');
rebundle();
});
}
rebundle();
}
function watch() {
return compile(true);
}
gulp.task('clean', function(cb) { del([$.dist], cb); });
gulp.task('jsBuild', function() { return compile(); });
gulp.task('jsWatch', function() { return watch(); });
gulp.task('setProduction', function() {$.env = 'production'; });
gulp.task('serve', function() {
browserSync.init({
server: {
baseDir: $.dist
},
files: [$.dist]
});
gulp.watch($.html, ['html']);
gulp.watch($.scss, ['sass']);
gulp.watch([$.js, $.tag], ['jsBuild']);
});
gulp.task('sass', function() {
var include = require('node-normalize-scss').with('./node_modules/csstyle');
gulp.src($.scss)
.pipe(sass({includePaths: include})
.on('error', function(err) { console.log(err); }))
.pipe(autoprefixer({
browsers: ['> 1%', 'last 2 versions', 'Android 4'],
cascade: false
}))
.pipe(gulp.dest($.dist))
.pipe(browserSync.stream());
});
gulp.task('html', function() {
gulp.src($.html)
.pipe(gulp.dest($.dist));
});
gulp.task('production', function(cb) {
$.env = 'production';
runSequence('clean', ['html', 'sass', 'jsBuild'], cb);
});
gulp.task('deploy', function() {
gulp.src($.dist + "**/*")
.pipe(ghPages());
});
gulp.task('default', function(cb) {
runSequence('clean', ['html', 'sass', 'jsWatch'], 'serve', cb);
});