-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
54 lines (45 loc) · 1.64 KB
/
index.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
'use strict';
var _ = require('lodash'),
webpackConfigFactory = require('./webpackConfigFactory'),
webpack = require('webpack-stream'),
gulplog = require('gulplog'),
notify = require('gulp-notify'),
plumber = require('gulp-plumber'),
named = require('vinyl-named');
module.exports = function (gulp, configExpr) {
return function (callback) {
var config = _.isFunction(configExpr) ? configExpr() : configExpr;
var webpackConfig = webpackConfigFactory(config);
var watch = config.watch || false,
isOld = config.old || false,
entry = config.entry,
destinations = _.isArray(config.destination) ? config.destination : [config.destination];
var firstBuildReady = false;
var done = function (err, stats) {
gulplog[stats.hasErrors() ? 'error' : 'info'](stats.toString({
colors: true
}));
if (!firstBuildReady) {
callback();
}
firstBuildReady = true;
};
var gulpPipe = gulp.src(entry)
.pipe(plumber({
errorHandler: function(err) {
notify.onError({
title: 'Webpack',
message: _.truncate(err.message, {
length: 250
})
})(err);
}
}))
.pipe(named())
.pipe(webpack(webpackConfig, null, done));
_.forEach(destinations, function (destination) {
gulpPipe.pipe(gulp.dest(destination));
});
return gulpPipe;
};
};