-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
121 lines (101 loc) · 2.81 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
120
121
'use strict';
/*eslint-env node*/
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var open = require('opn');
var lazypipe = require('lazypipe');
var rimraf = require('rimraf');
var runSequence = require('run-sequence');
var webpack = require('webpack');
var webpackStream = require('webpack-stream');
var WebpackDevServer = require('webpack-dev-server');
var makeWebpackConfig = require('./webpack.make');
var port = 9000;
var yeoman = {
app: 'app',
dist: 'dist'
};
var paths = {
scripts: [yeoman.app + '/**/*.js'],
views: {
main: yeoman.app + '/index.html'
}
};
////////////////////////
// Reusable pipelines //
////////////////////////
var lintScripts = lazypipe()
.pipe($.eslint, './.eslintrc.js')
.pipe($.eslint.format);
///////////
// Tasks //
///////////
gulp.task('webpack:dev', function () {
var webpackDevConfig = makeWebpackConfig({ DEV: true });
return gulp.src(webpackDevConfig.entry.app)
.pipe($.plumber())
.pipe(webpackStream(webpackDevConfig, webpack))
.pipe(gulp.dest('.tmp'));
});
gulp.task('webpack:dist', function () {
var webpackDistConfig = makeWebpackConfig({ BUILD: true });
return gulp.src(webpackDistConfig.entry.app)
.pipe(webpackStream(webpackDistConfig, webpack))
.on('error', () => {
this.emit('end'); // Recover from errors
})
.pipe(gulp.dest(yeoman.dist));
});
gulp.task('lint', function () {
return gulp.src(paths.scripts)
.pipe(lintScripts());
});
gulp.task('clean:tmp', function (cb) {
rimraf('./.tmp', cb);
});
gulp.task('watch', function () {
$.watch(paths.scripts, function () {
gulp.src(paths.scripts)
.pipe(lintScripts());
});
});
gulp.task('webpack-dev-server', function () {
var webpackDevConfig = makeWebpackConfig({ DEV: true });
webpackDevConfig.entry.app = [
'webpack-dev-server/client?http://localhost:' + port + '/',
'webpack/hot/dev-server',
webpackDevConfig.entry.app
];
new WebpackDevServer(webpack(webpackDevConfig), webpackDevConfig.devServer).listen(port, 'localhost', function () {
open('http://localhost:' + port);
});
});
gulp.task('serve', function (cb) {
runSequence(
'lint',
'webpack-dev-server',
'watch', cb);
});
///////////
// Build //
///////////
gulp.task('clean:dist', function (cb) {
rimraf('./' + yeoman.dist, cb);
});
gulp.task('images', function () {
return gulp.src(yeoman.app + '/images/**/*')
.pipe($.cache($.imagemin({
optimizationLevel: 5,
progressive: true,
interlaced: true
})))
.pipe(gulp.dest(yeoman.dist + '/images'));
});
gulp.task('copy:extras', function () {
return gulp.src(yeoman.app + '/*/.*', { dot: true })
.pipe(gulp.dest(yeoman.dist));
});
gulp.task('build', ['clean:dist'], function (cb) {
runSequence(['images', 'copy:extras', 'webpack:dist'], cb);
});
gulp.task('default', ['build']);