This repository was archived by the owner on Nov 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
84 lines (69 loc) · 2.27 KB
/
gulpfile.js
File metadata and controls
84 lines (69 loc) · 2.27 KB
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
const autoPrefixer = require('gulp-autoprefixer');
const browserify = require('browserify');
const concat = require('gulp-concat');
const gulp = require('gulp');
const gulpUtil = require('gulp-util');
const less = require('gulp-less');
const source = require('vinyl-source-stream');
const sourcemaps = require('gulp-sourcemaps');
const tsify = require('tsify');
const watchify = require('watchify');
const watchLess = require('gulp-watch-less');
const config = {
bowerPath: __dirname + '/bower_components',
cssPath: __dirname + '/www/assets/styles',
jsPath: __dirname + '/www/assets/scripts',
lessPath: __dirname + '/src/styles',
tsPath: __dirname + '/src/scripts',
};
const tsArgs = {
noImplicitAny: true,
target: 'ES5'
};
gulp.task('default', ['build']);
gulp.task('build', ['libs', 'scripts', 'styles']);
gulp.task('libs', () => gulp.src([
config.bowerPath + '/jquery/dist/jquery.js',
config.bowerPath + '/angular/angular.js',
config.bowerPath + '/angular-route/angular-route.js'], { base: config.bowerPath })
.pipe(sourcemaps.init())
.pipe(concat('lib.js'))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(config.jsPath)));
gulp.task('scripts',
() => bundleScripts(createBundler().plugin(tsify, tsArgs)));
gulp.task('styles',
() => compileStyles(gulp.src(config.lessPath + '/app.less')));
gulp.task('watch', ['watchScripts', 'watchStyles']);
gulp.task('watchScripts', () => {
const bundler = watchify(createBundler())
.plugin('tsify', tsArgs)
.on('update', bundle)
.on('log', gulpUtil.log);
function bundle() {
return bundleScripts(bundler);
}
return bundle();
});
gulp.task('watchStyles', ['styles'],
() => compileStyles(watchLess(config.lessPath + '/app.less')));
function createBundler() {
return browserify({
basedir: config.tsPath,
entries: [config.tsPath + '/app.ts'],
debug: true,
});
}
function bundleScripts(bundler) {
return bundler
.bundle()
.on('error', gulpUtil.log.bind(gulpUtil, 'Browserify Error'))
.pipe(source('app.js'))
.pipe(gulp.dest(config.jsPath));
}
function compileStyles(stream) {
return stream
.pipe(less())
.pipe(autoPrefixer())
.pipe(gulp.dest(config.cssPath));
}