-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
60 lines (50 loc) · 1.79 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
let gulp = require("gulp")
let stylus = require("gulp-stylus")
let gutil = require("gulp-util")
let rename = require("gulp-rename")
let file = require("gulp-file")
let uglify = require("gulp-uglify")
let source = require("vinyl-source-stream")
let buffer = require("vinyl-buffer")
let browserify = require("browserify")
let babelify = require("babelify")
let jstify = require("jstify")
let browserifyShim = require("browserify-shim")
let uglifyify = require("uglifyify")
let config = require("./config")
// TODO (PenguinToast): Handle dist better
function handleError(error) {
gutil.log(error.stack)
this.emit("end")
}
gulp.task("constants", () => {
let codeString = JSON.stringify(config.constants)
codeString = `export default ${codeString}`
return file(config.paths.dest.constants, codeString, { src: true })
.pipe(gulp.dest(config.paths.dest.constantsDir))
})
gulp.task("javascripts", ["constants"], () => (
browserify(config.paths.src.javascripts, config.plugin.browserify)
.transform(jstify, { noMinify: true })
.transform(babelify)
.transform(browserifyShim)
.transform({ global: true }, uglifyify)
.bundle()
.on("error", handleError)
.pipe(source(config.paths.dest.javascripts))
.pipe(config.production ? buffer() : gutil.noop())
.pipe(config.production ? uglify() : gutil.noop())
.pipe(gulp.dest(config.paths.dest.dir))
))
gulp.task("stylesheets", () => (
gulp.src(config.paths.src.stylesheets)
.pipe(stylus(config.plugin.stylus))
.pipe(rename(config.paths.dest.stylesheets))
.pipe(gulp.dest(config.paths.dest.dir))
))
gulp.task("watch", ["build"], () => {
gulp.watch("src/javascripts/**/*", ["javascripts"])
gulp.watch("src/stylesheets/*", ["stylesheets"])
})
gulp.task("build", ["javascripts", "stylesheets"])
gulp.task("default", ["watch"])