-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
74 lines (62 loc) · 2.16 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
'use strict'
const gulp = require('gulp')
const mocha = require('gulp-mocha')
const watchify = require('watchify')
const browserify = require('browserify')
const source = require('vinyl-source-stream')
const buffer = require('vinyl-buffer')
const logger = require('fancy-log')
const sourcemaps = require('gulp-sourcemaps')
const sass = require('gulp-sass')(require('node-sass'))
gulp.task('test', function () {
return gulp.src('test/*.js', { read: false })
.pipe(mocha({ reporter: 'nyan' }))
})
const opts = Object.assign({}, watchify.args, {
entries: './app/main.jsx',
extensions: ['.jsx'],
debug: true
})
const b = browserify(opts)
b.on('update', bundle(false)) // on any dep update, runs the bundler
b.on('log', logger) // output build logs to terminal
b.transform('babelify', { presets: ['@babel/preset-env', '@babel/preset-react'] })
function bundle (watch) {
return function () {
let target
if (watch) {
target = watchify(b)
} else {
target = b
}
return target.bundle()
// log errors if they happen
.on('error', (err) => logger.error('Browserify Error:', err))
.pipe(source('bundle.js'))
// optional, remove if you don't need to buffer file contents
.pipe(buffer())
// optional, remove if you dont want sourcemaps
.pipe(sourcemaps.init({ loadMaps: true })) // loads map from browserify file
// Add transformation tasks to the pipeline here.
.pipe(sourcemaps.write('./')) // writes .map file
.pipe(gulp.dest('./dist'))
}
}
gulp.task('copy-fonts', function () {
return gulp.src('./node_modules/bootstrap-sass/assets/fonts/**/*')
.pipe(gulp.dest('dist/fonts'))
})
gulp.task('sass', function () {
return gulp.src('./public/stylesheets/**.sass')
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dist/css'))
})
gulp.task('sass-watch', function () {
gulp.watch('./public/stylesheets/**.sass', ['sass'])
})
gulp.task('js', bundle(false))
gulp.task('js-watch', bundle(true))
gulp.task('watch', gulp.series('copy-fonts', 'sass', 'sass-watch', 'js-watch'))
gulp.task('build', gulp.series('copy-fonts', 'sass', 'js'))