-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
87 lines (75 loc) · 2.38 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
import gulp from 'gulp';
import source from 'vinyl-source-stream';
import notify from 'gulp-notify';
import nodemon from 'gulp-nodemon';
import sass from 'gulp-sass';
import postcss from 'gulp-postcss';
import imagemin from 'gulp-imagemin';
import sourcemaps from 'gulp-sourcemaps';
import babel from 'gulp-babel';
import webpack from 'webpack'
import webpackStream from 'webpack-stream';
import config from './webpack.config';
gulp.task('build', ['sass', 'images', 'server-run'], function() {
return gulp.src('client/app.js')
.pipe(notify('Starting Webpack Build'))
.pipe(webpackStream(config, webpack))
.pipe(notify('Build Finished'))
.pipe(gulp.dest('./public/js'));
});
gulp.task('webpack-watch', function() {
config.watch = true;
return gulp.src('client/app.js')
.pipe(notify('Watching Webpack Build'))
.pipe(webpackStream(config, webpack))
.on('error', () => {
this.emit('end')
})
.pipe(notify('Build Finished'))
.pipe(gulp.dest('./public/js'));
});
gulp.task('assets-watch', ['sass', 'images'], function() {
gulp.watch('./assets/scss/**/*', ['sass']);
gulp.watch('./public/images/*', ['images']);
});
gulp.task('server-copy', function() {
return gulp.src(['server/**/*', '!server/**/*.js'])
.pipe(gulp.dest('dist'))
});
gulp.task('server-build', ['server-copy'], function() {
return gulp.src('server/**/*.js')
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(babel())
.pipe(sourcemaps.write())
.pipe(gulp.dest('dist'))
});
gulp.task('sass', function() {
return gulp.src('./assets/scss/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(postcss())
.pipe(gulp.dest('./public/css'))
});
gulp.task('images', function() {
return gulp.src('./assets/images/**/*')
.pipe(imagemin({
progressive: true
}))
.pipe(gulp.dest('./public/images'));
});
gulp.task('dev-env', function() {
return process.env.NODE_ENV = 'development';
})
gulp.task('prod-env', function() {
return process.env.NODE_ENV = 'production';
})
gulp.task('run', ['server-build'], function() {
const forbidden = ['client', 'node_modules', 'public', 'dist'];
nodemon({
script: './bin/www',
ext: 'js',
ignore: forbidden
})
.on('restart', ['server-build']);
});
gulp.task('default', ['dev-env', 'webpack-watch', /* 'assets-watch', */ 'run']);
gulp.task('production', ['prod-env', 'webpack-watch', 'assets-watch', 'run'])