-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
98 lines (84 loc) · 2.71 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
"use strict"; // I like to begin any JS file by adding this to the top
var gulp = require('gulp');
var connect = require('gulp-connect'); // Runs a local dev server
var browserify = require('browserify'); // Bundles JS
var reactify = require('reactify'); // Transforms React JSX to JS
var source = require('vinyl-source-stream'); // Use conventional text streams with Gulp
var concat = require('gulp-concat'); // concatenates files
var lint = require('gulp-eslint'); // Lint JS files, including JSX
var nodemon = require('gulp-nodemon');
var exec = require('child_process').exec;
var config = {
paths: {
html: './src/*.html',
js: './src/**/*.js',
images: './src/images/*',
css: [
'node_modules/bootstrap/dist/css/bootstrap.min.css',
'node_modules/bootstrap/dist/css/bootstrap-theme.min.css',
'node_modules/toastr/build/toastr.min.css',
'src/css/*.css'
],
jslib: [
'node_modules/bootstrap/dist/js/bootstrap.min.js',
'node_modules/jquery/dist/jquery.min.js',
'node_modules/toastr/build/toastr.min.js'
],
dist: './dist',
mainJs: './src/main.js',
appServer: 'app-server.js'
}
// We define path using globs, which look like Regex
}
// Runs node server
gulp.task('run', function (cb) {
nodemon({
script : './app-server.js',
watch : [config.paths.js, config.paths.appServer]
});
});
gulp.task('html', function() {
gulp.src(config.paths.html)
.pipe(gulp.dest(config.paths.dist))
.pipe(connect.reload());
// we are saying: go get any html files, put them in the dest path, reload using connect
});
gulp.task('jslib', function() {
gulp.src(config.paths.jslib)
.pipe(gulp.dest(config.paths.dist + '/scripts'))
.pipe(connect.reload());
});
gulp.task('js', function() {
browserify(config.paths.mainJs)
.transform(reactify)
.bundle()
.on('error', console.error.bind(console))
.pipe(source('bundle.js'))
.pipe(gulp.dest(config.paths.dist + '/scripts'))
.pipe(connect.reload());
});
gulp.task('css', function() {
gulp.src(config.paths.css)
.pipe(concat('bundle.css'))
.pipe(gulp.dest(config.paths.dist + '/css'));
});
// Migrates images to dist folder
gulp.task('images', function() {
gulp.src(config.paths.images)
.pipe(gulp.dest(config.paths.dist + '/images'))
.pipe(connect.reload());
// publish favicon
gulp.src('./src/favicon.ico')
.pipe(gulp.dest(config.paths.dist));
});
gulp.task('lint', function() {
return gulp.src(config.paths.js)
.pipe(lint({config: 'eslint.config.json'}))
.pipe(lint.format());
});
gulp.task('watch', function() {
gulp.watch(config.paths.html, ['html']);
gulp.watch(config.paths.css, ['css']);
gulp.watch(config.paths.js, ['js', 'lint']);
});
gulp.task('default', ['html', 'jslib', 'js', 'css', 'images', 'lint', 'run', 'watch']);