-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
127 lines (112 loc) · 3.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
122
123
124
125
126
127
var gulp = require('gulp');
/* DEV FOLDERS */
var appDev = 'client/';
var assetsDev = 'client/assets/';
/* PROD FOLDERS */
var appProd = 'app/';
var assetsProd = 'app/assets/';
var BROWSER_SYNC_RELOAD_DELAY = 500;
var ext_replace = require('gulp-ext-replace'),
postcss = require('gulp-postcss'),
sourcemaps = require('gulp-sourcemaps'),
autoprefixer = require('autoprefixer'),
precss = require('precss'),
cssnano = require('cssnano'),
concat = require('gulp-concat'),
rename = require('gulp-rename'),
uglify = require('gulp-uglify'),
typescript = require('gulp-typescript'),
imagemin = require('gulp-imagemin'),
nodemon = require('gulp-nodemon'),
browserSync = require('browser-sync');
var tsProject = typescript.createProject('tsconfig.json');
gulp.task('build-vendor', function() {
return gulp.src([
/* AnguLAR 2 required libraries */
/* IE required polyfills, in this exact order */
'node_modules/es6-shim/es6-shim.min.js',
'node_modules/systemjs/dist/system-polyfills.js',
'node_modules/angular2/es6/dev/src/testing/shims_for_IE.js',
'node_modules/angular2/bundles/angular2-polyfills.js',
'node_modules/systemjs/dist/system.src.js',
'node_modules/rxjs/bundles/Rx.js',
'node_modules/angular2/bundles/angular2.js',
'node_modules/angular2/bundles/router.dev.js',
'node_modules/angular2/bundles/http.js'
])
.pipe(concat('vendor.js'))
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(gulp.dest('app/'));
});
gulp.task('build-ts', function () {
return gulp.src(appDev + '**/*.ts')
.pipe(sourcemaps.init())
.pipe(typescript(tsProject))
.pipe(sourcemaps.write())
//.pipe(uglify())
.pipe(gulp.dest(appProd));
});
gulp.task('build-css', function () {
return gulp.src(assetsDev + 'styles/*.scss')
.pipe(sourcemaps.init())
.pipe(postcss([precss, autoprefixer, cssnano]))
.pipe(sourcemaps.write())
.pipe(ext_replace('.css'))
.pipe(gulp.dest(assetsProd + 'styles/'));
});
gulp.task('build-img', function () {
return gulp.src(assetsDev + 'img/**/*')
.pipe(imagemin({
progressive: true
}))
.pipe(gulp.dest(assetsProd + 'img/'));
});
gulp.task('build-html', function () {
return gulp.src(appDev + '**/*.html')
.pipe(gulp.dest(appProd));
});
gulp.task('nodemon', function(cb) {
var called = false;
return nodemon({
// nodemon our expressjs server
script: 'server.js',
// watch core server file(s) that require server restart on change
watch: ['server.js', 'server/**/*.js']
})
.on('start', function onStart() {
// ensure start only got called once
if (!called) { cb(); }
called = true;
})
.on('restart', function onRestart() {
// reload connected browsers after a slight delay
setTimeout(function reload() {
browserSync.reload({
stream: false
});
}, BROWSER_SYNC_RELOAD_DELAY);
});
});
gulp.task('browser-sync', ['nodemon'], function() {
// for more browser-sync config options: http://www.browsersync.io/docs/options/
browserSync({
// informs browser-sync to proxy our expressjs app which would run at the following location
proxy: 'http://localhost:3001',
// informs browser-sync to use the following port for the proxied app
// notice that the default port is 3000, which would clash with our expressjs
port: 4000,
// open the proxied app in chrome
//browser: 'google chrome'
});
});
gulp.task('bs-reload', function() {
browserSync.reload();
});
gulp.task('watch', function () {
gulp.watch(appDev + '**/*.ts', ['build-ts', browserSync.reload]);
gulp.watch(assetsDev + 'styles/**/*.scss', ['build-css', browserSync.reload]);
gulp.watch(assetsDev + 'img/*', ['build-img', browserSync.reload]);
gulp.watch('*.html', ['bs-reload']);
});
gulp.task('default', ['build-vendor', 'watch', 'build-ts', 'build-css', 'browser-sync']);