-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
145 lines (127 loc) · 3.62 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
var gulp = require('gulp')
var $ = require('gulp-load-plugins')()
var runSequence = require('run-sequence')
var del = require('del')
var sassImporter = require('sass-importer-npm')
var autoprefixer = require('autoprefixer')
// CLEAN DIST FILES
gulp.task('clean', function (cb) {
del([
'./assets/css',
'./assets/js',
'./assets/vendor'
]).then(function () {
cb()
})
})
// Copy vendor libraries from ./node_modules to ./assets/vendor
// Useful when publishing to a CDN
gulp.task('copy', function () {
return gulp.src([
'simplebar/dist/simplebar.css',
'systemjs/dist/system.src.js',
], {
cwd: 'node_modules'
})
.pipe(gulp.dest('./assets/vendor'))
})
// Compile TypeScript from ./app to ./assets/js
// FOR DEVELOPMENT: use "npm start" or "npm run tsc" instead of the gulp tasks
var tsProject = $.typescript.createProject('./tsconfig.json', {
sortOutput: true
})
gulp.task('ts', function() {
var tsResult = tsProject.src('./app/**/*.ts')
.pipe($.preprocess())
.pipe($.sourcemaps.init())
.pipe($.typescript(tsProject))
return tsResult.js
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('./assets/js'))
})
// (Watch) Compile TypeScript from ./app to ./assets/js
gulp.task('watch:ts', function() {
gulp.watch('./app/**/*.ts', ['build:ts'])
})
function build(minify) {
minify = minify || false
var path = require('path')
var Builder = require('systemjs-builder')
var builder = new Builder('./', './systemjs.config.js')
return builder
.bundle('./assets/js/main.js', './assets/js/app.bundle.js', { minify: minify, sourceMaps: !minify })
.catch(function(err) {
console.log('Build error');
console.log(err);
})
}
// Create production bundle to ./assets/js/app.bundle.js
// AFTER compiling TypeScript from ./app to ./assets/js
gulp.task('build:ts', ['ts'], function() {
return build()
})
// Create production bundle (minified) to ./assets/js/app.bundle.js
// AFTER compiling TypeScript from ./app to ./asstes/js
gulp.task('release:ts', ['ts'], function() {
return build(true)
})
// Create production bundle to ./assets/js/app.bundle.js
// WITHOUT compiling TypeScript
gulp.task('build:js', function() {
return build()
})
// Create production bundle (minified) to ./assets/js/app.bundle.js
// WITHOUT compiling TypeScript
gulp.task('release:js', function() {
return build(true)
})
function sass(minify) {
minify = minify || false
return gulp.src('./assets/sass/app.scss')
// (optional) sourcemaps
.pipe($.if(!minify, $.sourcemaps.init()))
// Compile Sass
.pipe($.sass({
// Resolve Sass file imports from node_modules
importer: sassImporter
})
// Handle errors
.on('error', $.sass.logError))
// Post CSS
.pipe($.postcss([
// autoprefixer
autoprefixer({ browsers: ['last 2 versions'] })
]))
// (optional) Minify CSS
.pipe($.if(minify, $.cleanCss()))
// (optional) Write .map file
.pipe($.if(!minify, $.sourcemaps.write('.')))
// Write CSS file
.pipe(gulp.dest('./assets/css'))
}
// Compile Sass from ./app/assets/sass to ./app/assets/css (not minified, with sourcemaps)
gulp.task('build:sass', function () {
return sass()
})
// Compile Sass from ./app/assets/sass to ./app/assets/css (minified, without sourcemaps)
gulp.task('release:sass', function () {
return sass(true)
})
// Watch Sass
gulp.task('watch:sass', function () {
gulp.watch('./assets/sass/**/*', ['build:sass'])
})
gulp.task('build', function(callback) {
runSequence(
'clean',
['copy', 'ts', 'build:sass'],
callback)
})
gulp.task('release', function(callback) {
runSequence(
'clean',
['copy', 'release:ts', 'release:sass'],
callback)
})
gulp.task('watch', ['watch:ts', 'watch:sass'])
gulp.task('default', ['build'])