-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
147 lines (126 loc) · 4.67 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
/******************************************************************************
* Gulpfile
* Be sure to run `npm install` for `gulp` and the following tasks to be
* available from the command line. All tasks are run using `gulp taskName`.
******************************************************************************/
var gulp = require('gulp'),
tslint = require("gulp-tslint"),
webpack = require('webpack'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
watch = require('gulp-watch'),
del = require('del');
var IONIC_DIR = "node_modules/ionic-angular/"
/******************************************************************************
* watch
* Build the app and watch for source file changes.
******************************************************************************/
gulp.task('watch', ['sass', 'copy.fonts', 'copy.html'], function(done) {
watch('www/app/**/*.scss', function() {
gulp.start('sass');
});
watch('www/app/**/*.html', function() {
gulp.start('copy.html');
});
bundle(true, done);
});
/******************************************************************************
* build
* Build the app once, without watching for source file changes.
******************************************************************************/
gulp.task('build', ['sass', 'copy.fonts', 'copy.html'], function(done) {
bundle(false, done);
});
/******************************************************************************
* sass
* Convert Sass files to a single bundled CSS file. Uses auto-prefixer
* to automatically add required vendor prefixes when needed.
******************************************************************************/
gulp.task('sass', function() {
var autoprefixerOpts = {
browsers: [
'last 2 versions',
'iOS >= 7',
'Android >= 4',
'Explorer >= 10',
'ExplorerMobile >= 11'
],
cascade: false
};
return gulp.src('app/theme/app.+(ios|md).scss')
.pipe(sass({
includePaths: [
IONIC_DIR,
'node_modules/ionicons/dist/scss'
]
}))
.on('error', function(err) {
console.error(err.message);
this.emit('end');
})
.pipe(autoprefixer(autoprefixerOpts))
.pipe(gulp.dest('www/build/css'))
});
/******************************************************************************
* copy.fonts
* Copy Ionic font files to build directory.
******************************************************************************/
gulp.task('copy.fonts', function() {
return gulp.src(IONIC_DIR + 'fonts/**/*.+(ttf|woff|woff2)')
.pipe(gulp.dest('www/build/fonts'));
});
/******************************************************************************
* copy.html
* Copy html files to build directory.
******************************************************************************/
gulp.task('copy.html', function() {
return gulp.src('app/**/*.html')
.pipe(gulp.dest('www/build'));
});
/******************************************************************************
* clean
* Delete previous build files.
******************************************************************************/
gulp.task('clean', function(done) {
del(['www/build'], done);
});
/******************************************************************************
* tslint
* Lint all TypeScript files
******************************************************************************/
gulp.task("tslint", () =>
gulp.src("app/**/*.ts")
.pipe(tslint())
.pipe(tslint.report("verbose"))
);
/******************************************************************************
* Bundle
* Transpiles source files and bundles them into build directory using webpack.
******************************************************************************/
function bundle(watch, cb) {
// prevent gulp calling done callback more than once when watching
var firstTime = true;
// load webpack config
var config = require('./webpack.config.js');
// https://github.com/webpack/docs/wiki/node.js-api#statstojsonoptions
var statsOptions = {
'colors': true,
'modules': false,
'chunks': false,
'exclude': ['node_modules']
}
var compiler = webpack(config);
if (watch) {
compiler.watch(null, compileHandler);
} else {
compiler.run(compileHandler);
}
function compileHandler(err, stats) {
if (firstTime) {
firstTime = false;
cb();
}
// print build stats and errors
console.log(stats.toString(statsOptions));
}
}