-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.babel.js
115 lines (97 loc) · 2.79 KB
/
gulpfile.babel.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
import gulp from 'gulp';
import sass from 'gulp-sass';
import sourcemaps from 'gulp-sourcemaps';
import autoprefixer from 'gulp-autoprefixer';
import cleanCSS from 'gulp-clean-css';
import imagemin from 'gulp-imagemin';
import webpack from 'gulp-webpack';
import nodemon from 'gulp-nodemon';
import mocha from 'gulp-mocha';
import babel from 'gulp-babel';
import compiler from 'babel-register';
import { spawn } from 'child_process';
import config from './webpack.config.babel';
/************************************/
// test tasks
gulp.task('test', function() {
return gulp.src([
'!node_modules/**/*.js',
'!dist/**/*.js',
'**/*.spec.js'
])
.pipe(mocha({
require: ['./server/utils/jsdom'],
timeout: 10000,
compilers: {
js: compiler
}
}));
});
/************************************/
// asset tasks
gulp.task('styles', function() {
return gulp.src('assets/scss/style.scss')
.pipe(sass().on('error', sass.logError))
.pipe(sourcemaps.init())
.pipe(autoprefixer({
browsers: ['last 2 versions']
}))
.pipe(cleanCSS({compatibility: 'ie8'}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('public/css'));
});
gulp.task('images', function() {
return gulp.src('assets/images/*')
.pipe(imagemin())
.pipe(gulp.dest('public/images'));
});
gulp.task('assets-watch', ['assets-build'], function() {
gulp.watch('assets/scss/**/*.scss', ['styles']);
gulp.watch('assets/images/**/*', ['images']);
});
gulp.task('assets-build', ['styles', 'images']);
/************************************/
// client tasks
const clientBuild = function() {
return gulp.src('client/index.js')
.pipe(webpack(config))
.pipe(gulp.dest('public/js'));
};
gulp.task('client-watch', function() {
config.watch = true;
return clientBuild();
});
gulp.task('client-build', function() {
return clientBuild();
});
/************************************/
// server tasks
gulp.task('server-build', function() {
return gulp.src(['server/**/*'])
.pipe(sourcemaps.init())
.pipe(babel())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist'));
});
gulp.task('server-watch-and-run', ['server-build'], function() {
nodemon({
script: 'dist/bin/www',
ext: 'js',
tasks: ['server-build'],
ignore: [
'node_modules',
'public',
'dist',
]
});
});
gulp.task("server-build-and-run", ['server-build'], function() {
const server = spawn('node', ['dist/bin/www']);
server.stdout.pipe(process.stdout);
server.stderr.pipe(process.stderr);
});
/************************************/
// default task
const development = ['assets-watch', 'client-watch', 'server-watch-and-run'];
const production = ['assets-build', 'client-build', 'server-build-and-run'];
gulp.task('default', process.env.NODE_ENV === 'development' ? development : production);