-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
116 lines (96 loc) · 3.05 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
'use strict';
var gulp = require('gulp'),
del = require('del'),
path = require('path'),
react = require('gulp-react'),
webpackConfig = require('./webpack.config.js');
// Loads plugins
var $ = require('gulp-load-plugins')();
// Copy jsx files to destination and convert to js
gulp.task('jsx', function () {
return gulp.src('app/scripts/**/*.jsx')
// Turn React JSX syntax into regular javascript
.pipe(react({harmony: true}))
.pipe(gulp.dest('build/scripts/'));
});
// Bundle jsx files
gulp.task('webpack', function() {
return $.webpack(webpackConfig)
// gulp-webpack needs to pipe to dest
.pipe(gulp.dest('build/scripts/'));
});
// Copy js files to destination
gulp.task('javascript', function () {
return gulp.src('app/scripts/**/*.js')
.pipe(gulp.dest('build/scripts/'));
});
// Copy bower files to destination
gulp.task('bower', function() {
gulp.src('app/bower_components/**/*.js', {base: 'app/bower_components'})
.pipe(gulp.dest('build/bower_components/'));
});
gulp.task('html', function () {
return gulp.src('app/*.html')
.pipe($.useref())
.pipe(gulp.dest('build'));
});
gulp.task('images', function () {
return gulp.src('app/images/**/*')
.pipe($.cache($.imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true
})))
.pipe(gulp.dest('build/images/'));
});
// Commented out bc gulp-ruby-sass doesn't work well on Heroku
// Styles
//gulp.task('styles', function () {
// return gulp.src('app/styles/main.scss')
// .pipe($.rubySass({
// style: 'expanded',
// precision: 10,
// loadPath: process.cwd() + '/app/bower_components'
// }))
// .pipe($.autoprefixer('last 5 version'))
// .pipe(gulp.dest('build/styles'));
//});
gulp.task('css', function () {
return gulp.src('app/styles/main.css')
.pipe(gulp.dest('build/styles'));
});
gulp.task('clean', function(cb) {
return cb(del.sync(['build']));
});
// Bundle
gulp.task('bundle', ['images', 'html', 'css', 'bower', 'jsx', 'webpack', 'javascript'], function(){
var assets = $.useref.assets();
return gulp.src('app/*.html')
.pipe(assets)
.pipe(assets.restore())
.pipe($.useref())
.pipe(gulp.dest('build'));
});
// Default task
gulp.task('default', ['clean', 'bundle']);
// Watch
gulp.task('watch', ['bundle'], function () {
// Watch .jsx or .js files
gulp.watch(['app/scripts/**/*.js', 'app/scripts/**/*.jsx'], ['jsx', 'javascript', 'webpack']);
// Watch .html files
gulp.watch('app/**/*.html', ['html']);
// Watch .scss files
// gulp.watch('app/styles/**/*.scss', ['styles']);
// Watch .css files
gulp.watch('app/styles/**/*.css', ['css']);
// Watch image files
gulp.watch('app/images/**/*', ['images']);
// Start up the server and have it reload when anything in the
// ./build/ directory changes or the server.js file.
$.nodemon({
script: 'server.js',
watch: ['build', 'server.js'],
ext: 'js html',
nodeArgs: ['--debug']
});
});