-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
103 lines (93 loc) · 2.65 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
var gulp = require('gulp');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var shell = require('gulp-shell');
var less = require('gulp-less');
var traceur = require('gulp-traceur');
var webserver = require('gulp-webserver');
// run init tasks
gulp.task('default', ['dependencies', 'angular2', 'js', 'html', 'css', 'less']);
// run development task
gulp.task('dev', ['watch', 'serve']);
// serve the build dir
gulp.task('serve', function() {
gulp.src('build')
.pipe(webserver({
host: '0.0.0.0',
open: true
}));
});
// watch for changes and run the relevant task
gulp.task('watch', function() {
gulp.watch('src/**/*.js', ['js']);
gulp.watch('src/**/*.html', ['html']);
gulp.watch('src/**/*.css', ['css']);
gulp.watch('src/**/*.less', ['less']);
});
// move dependencies into build dir
gulp.task('dependencies', function() {
return gulp.src([
'node_modules/angular2/node_modules/rx/dist/rx.all.js',
'node_modules/angular2/node_modules/traceur/bin/traceur.js',
'node_modules/angular2/node_modules/traceur/bin/traceur-runtime.js',
'node_modules/angular2/node_modules/zone.js/zone.js',
'node_modules/es6-module-loader/dist/es6-module-loader.js',
'node_modules/es6-module-loader/dist/es6-module-loader.js.map',
'node_modules/systemjs/dist/system.js',
'node_modules/systemjs/dist/system.js.map'
])
.pipe(gulp.dest('build/lib'));
});
// tanspile, concat & move angular
gulp.task('angular2', function() {
return gulp.src([
traceur.RUNTIME_PATH,
'node_modules/angular2/es6/prod/*.es6',
'node_modules/angular2/es6/prod/src/**/*.es6'
], {
base: 'node_modules/angular2/es6/prod'
})
.pipe(rename(function(path) {
path.dirname = 'angular2/' + path.dirname;
path.extname = '';
}))
.pipe(traceur({
modules: 'instantiate',
moduleName: true
}))
.pipe(concat('angular2.js'))
.pipe(gulp.dest('build/lib'));
});
// transpile & move js
gulp.task('js', function() {
return gulp.src('src/**/*.js')
.pipe(rename({
extname: ''
}))
.pipe(traceur({
modules: 'instantiate',
moduleName: true,
annotations: true,
types: true
}))
.pipe(rename({
extname: '.js'
}))
.pipe(gulp.dest('build'));
});
// move html
gulp.task('html', function() {
return gulp.src('src/**/*.html')
.pipe(gulp.dest('build'))
});
// move css
gulp.task('css', function() {
return gulp.src('src/**/*.css')
.pipe(gulp.dest('build/css'))
});
// less
gulp.task('less', function() {
return gulp.src('./src/less/main.less')
.pipe(less())
.pipe(gulp.dest('build/css/'))
});