This repository has been archived by the owner on Jul 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
67 lines (60 loc) · 1.72 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
55
56
57
58
59
60
61
62
63
64
65
66
67
const log = require('fancy-log');
const webpack = require('webpack');
const PluginError = require('plugin-error');
const config = require('./webpack.config');
const releaseConfig = require('./webpack.config.release');
const handleWebpackOutput = (err, stats) => {
if (err) throw new PluginError('tsPipeline', err);
log(
'[tsPipeline]',
stats.toString({
colors: true,
chunks: false
})
);
};
const getDevCompiler = (options) => {
return webpack(config(options));
};
const getReleaseCompiler = (options) => {
return webpack(releaseConfig(options));
};
const registerBuildGulpTasks = (gulp, options) => {
gulp.task('tsPipeline:build:dev', (done) => {
const compiler = getDevCompiler(options);
compiler.run((err, stats) => {
handleWebpackOutput(err, stats);
if (stats && stats.hasErrors()) {
return done(new Error('typescript compilation failed'));
}
done();
});
});
gulp.task('tsPipeline:build:release', (done) => {
const compiler = getReleaseCompiler(options);
compiler.run((err, stats) => {
handleWebpackOutput(err, stats);
if (stats && stats.hasErrors()) {
return done(new Error('typescript compilation failed'));
}
done();
});
});
gulp.task('tsPipeline:watch', () => {
const compiler = getDevCompiler(options);
compiler.watch(
{
aggregateTimeout: 300, // wait so long for more changes
poll: 2000 // windows needs polling to pick up changes :(
},
(err, stats) => {
handleWebpackOutput(err, stats);
}
);
});
};
module.exports = {
registerBuildGulpTasks: registerBuildGulpTasks,
getDevCompiler: getDevCompiler,
getReleaseCompiler: getReleaseCompiler
};