-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
175 lines (159 loc) · 4.71 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
var gulp = require('gulp');
var shell = require('gulp-shell');
var clean = require('gulp-clean');
var htmlreplace = require('gulp-html-replace');
var runSequence = require('run-sequence');
var Builder = require('systemjs-builder');
var builder = new Builder('', 'src/systemjs.config.js');
var sourcemaps = require('gulp-sourcemaps');
var typescript = require('gulp-typescript');
var uglify = require('gulp-uglifyjs');
var less = require('gulp-less');
var watchLess = require('gulp-watch-less');
var cleanCSS = require('gulp-clean-css');
var bundleHash = new Date().getTime();
var mainBundleName = bundleHash + '.main.bundle.js';
var vendorBundleName = bundleHash + '.vendor.bundle.js';
var rename = require("gulp-rename");
var minify = require("gulp-minify");
var cleanCSS = require('gulp-clean-css');
var pump = require('pump');
// This is main task for production use
gulp.task('dist', function (done) {
runSequence('clean', 'compile_ts', 'bundle', 'copy:assets', function () {
done();
});
});
gulp.task('bundle', ['bundle:vendor', 'bundle:app'], function () {
return gulp.src('src/index.public.html')
.pipe(htmlreplace({
'app': mainBundleName,
'vendor': vendorBundleName
}))
.pipe(rename('index.html'))
.pipe(gulp.dest('./public'));
});
gulp.task('bundle:vendor', function () {
return builder
.buildStatic('src/vendor.js', './public/' + vendorBundleName)
.catch(function (err) {
console.log('Vendor bundle error');
console.log(err);
});
});
gulp.task('bundle:app', function () {
return builder
.buildStatic('src/app/NgModule.js', './public/' + mainBundleName)
.catch(function (err) {
console.log('App bundle error');
console.log(err);
});
});
gulp.task('compile_ts', ['clean:ts'], function () {
return gulp
.src([
"src/**/*.ts"
])
.pipe(sourcemaps.init())
.pipe(typescript({
"module": "system",
"moduleResolution": "node",
"target": "ES5",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": true,
"typeRoots": [
"./node_modules/@types"
],
"lib": [
"es2016",
"dom"
]
}))
}
);
gulp.task('copy:assets', function () {
return gulp.src([
'./src/assets/**/*',
'./src/css/styles.css',
'./src/data/**/*',
'./src/templates/**/*',
], {base: "./src"})
.pipe(gulp.dest('./public'));
});
gulp.task('copy:app', function () {
return gulp.src([
'./src/**/*.js',
'./src/index.html',
], {base: "./src"})
.pipe(gulp.dest('./public'));
});
gulp.task('copy:dependencies', function () {
return gulp.src([
'./node_modules/@angular/**/*.js',
'./node_modules/mapbox-gl/dist/**/*.js',
'./node_modules/rxjs/**/*.js',
'./node_modules/core-js/client/shim.min.js',
'./node_modules/zone.js/dist/zone.js',
'./node_modules/reflect-metadata/Reflect.js',
'./node_modules/systemjs/dist/system.src.js',
], {base: "."})
.pipe(gulp.dest('./public'));
});
gulp.task('clean', ['clean:ts', 'clean:dist']);
gulp.task('clean:dist', function () {
return gulp.src(['./public'], {read: false})
.pipe(clean());
});
gulp.task('minify', ['minify:dist', 'minify:js', 'minify:css']);
gulp.task('minify:dist', function (cb) {
pump([
gulp.src('./public/**/*.js'),
uglify({
compress: true
}),
gulp.dest('./public')
],
cb
);
});
gulp.task('minify:js', function () {
return gulp.src('public/*.js')
.pipe(minify({
ext: {
min: 'bundle.js'
}
}))
.pipe(gulp.dest('public'));
});
gulp.task('minify:css', function () {
return gulp.src('public/css/*.css')
.pipe(cleanCSS({compatibility: 'ie8'}))
.pipe(gulp.dest('public/css/'))
});
gulp.task('clean:ts', function () {
return gulp.src(['./public/**/*.js', './public/**/*.js.map'], {read: false})
.pipe(clean());
});
gulp.task('clean:css', function () {
return gulp.src(['./public/css/styles.css'], {read: false})
.pipe(clean());
});
gulp.task('less', ['clean:css', 'less:c']);
gulp.task('less:c', function () {
return gulp.src(`src/css/styles.less`)
// .pipe(watchLess('src/css/styles.less'))
.pipe(less().on('error', function (err) {
console.log(err);
this.emit("end");
}))
// .pipe(cleanCSS({compatibility: 'ie8'}))
.pipe(gulp.dest(`src/css/`));
});
// This is main task for production use
gulp.task('dist_uncompressed', function (done) {
runSequence('compile_ts', 'copy:app', 'copy:assets', 'copy:dependencies', function () {
done();
});
});