-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
62 lines (54 loc) · 1.77 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
var gulp = require('gulp');
var tsc = require('gulp-typescript');
var merge = require('merge-stream');
const webpack = require('webpack');
const webpackConfig = require('./webpack.config.js');
var paths = {
typescript: './src/ts/**/*.ts',
javascript: './src/js/**/*.js',
css: './src/css/**/*.css',
nodemodules: [
'./node_modules/three/build/three.min.js',
]
};
// Compile own TypeScript
gulp.task('typescript', function(done) {
var tsProject = tsc.createProject('tsconfig.json');
var tsResult = gulp.src([paths.typescript])
.pipe(tsProject());
return merge(tsResult, tsResult.js)
.pipe(gulp.dest('./src/js'));
});
// Copy external dependencies
gulp.task('copy-dependencies', function(done) {
gulp.src('./node_modules/object-hash/dist/object_hash.js').pipe(gulp.dest('./src/js'));
done();
});
// Copy three.js to examples folder where it is imported externally
gulp.task('copy-node-modules', function(done) {
gulp.src(paths.nodemodules).pipe(gulp.dest('./examples/js'));
done();
});
// Run webpack
gulp.task('webpack', function(done) {
return new Promise((resolve, reject) => {
webpack(webpackConfig, (err, stats) => {
if (err) {
return reject(err);
}
if (stats.hasErrors()) {
return reject(new Error(stats.compilation.errors.join('\n')));
}
resolve();
});
});
});
// Build task
gulp.task('build', gulp.series("copy-dependencies", "typescript", "copy-node-modules", "webpack"));
// Development task
gulp.task('develop', function(done) {
gulp.watch([paths.typescript], gulp.series("typescript", "webpack"));
done();
});
// The default task (called when you run `gulp` from cli)
gulp.task('default', gulp.series("build", "develop"));