-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
119 lines (91 loc) · 2.37 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
'use strict'
let gulp = require('gulp')
let gutil = require('gulp-util')
let browserify = require('browserify')
let watchify = require('watchify')
let source = require('vinyl-source-stream')
let plugins = require('gulp-load-plugins')()
let browserSync = require('browser-sync').create()
let rimraf = require('rimraf')
let runSequence = require('run-sequence')
let babelify = require('babelify')
let reload = browserSync.reload
let paths = {
vendor: {
bootstrap: 'public/vendor/bootstrap'
}
}
/**
* Asset pipeline
*/
let bundleOptions = {
entries: ['app/assets/javascripts/app.js'],
debug: true
}
function bundleFile(file) {
let bundler = watchify(browserify({
entries: [`app/assets/javascripts/${file}.js`],
debug: true
}))
bundler.transform(babelify)
bundler.on('update', () => {
gutil.log(`Bundling ${file}.js..`)
bundle()
})
return bundler.bundle()
.on('error', gutil.log.bind(gutil, 'Browserify error'))
.pipe(source(`${file}.js`))
.pipe(gulp.dest('public/js'))
}
function bundle() {
let files = ['app']
files.forEach(bundleFile)
}
gulp.task('bundle', bundle)
/**
* Sass
*/
gulp.task('sass', () =>
gulp.src('app/assets/stylesheets/*.scss')
.pipe(plugins.sass().on('error', plugins.sass.logError))
.pipe(gulp.dest('public/css'))
.pipe(browserSync.stream())
)
gulp.task('sass:watch', () =>
gulp.watch('app/assets/stylesheets/*.scss', ['sass']))
/**
* BrowserSync
*/
gulp.task('browser-sync', () => {
browserSync.init({
proxy: 'localhost:3000',
port: 3001,
open: false,
ui: {
port: 3002
}
})
gulp.watch('public/js/*.js', reload)
gulp.watch('public/theme/**/*.js', reload)
gulp.watch('app/views/**/*.html.erb').on('change', reload)
})
/**
* Standard build task
* - copies bootstrap assets
*/
gulp.task('copy', () => {
gulp.src('node_modules/bootstrap/dist/**/*.*')
.pipe(gulp.dest(paths.vendor.bootstrap))
})
gulp.task('clean', (done) => {
gutil.log('Removing bootstrap')
rimraf(paths.vendor.bootstrap, {}, done)
})
gulp.task('build', ['copy'])
gulp.task('rebuild', done => runSequence('clean', 'build', done))
/**
* Server task
*/
gulp.task('server', ['build', 'bundle', 'sass:watch', 'browser-sync'], plugins.shell.task([
'rails server'
]))