-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
104 lines (81 loc) · 2.76 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
/* ------------------------
* Dependencies
* ----------------------- */
var gulp = require('gulp'),
$ = require('gulp-load-plugins')();
/* ----------------------------------------
* Paths; all paths and globs used in tasks
* ---------------------------------------- */
var paths = {
src: {},
build: {}
};
// browser
paths.src.root = './src/';
paths.src.appScriptsRoot = paths.src.root + 'scripts/';
paths.src.appScripts = paths.src.appScriptsRoot + '*.coffee';
paths.src.appEntryScript = paths.src.appScriptsRoot + 'app.coffee';
paths.src.fonts = paths.src.root + 'fonts/*';
paths.src.images = paths.src.root + 'images/*';
paths.src.stylesRoot = paths.src.root + 'styles/';
paths.src.styles = paths.src.stylesRoot + '*.less';
paths.src.styleEntryFile = paths.src.stylesRoot + 'app.less';
paths.src.templatesRoot = paths.src.root + 'templates/';
paths.src.templates = paths.src.templatesRoot + '*.html';
paths.src.dependencies = paths.src.root + 'third-party/**';
// public
paths.build.root = './build/';
paths.build.cssRoot = paths.build.root + 'css';
paths.build.fontsRoot = paths.build.root + 'fonts';
paths.build.imagesRoot = paths.build.root + 'images';
paths.build.browserScriptsRoot = paths.build.root + 'js';
paths.build.dependencies = paths.build.root + 'node_modules';
gulp.task('default', ['compile']);
gulp.task('compile', ['fonts', 'images', 'templates', 'scripts', 'styles', 'third-party']);
gulp.task('clean', function(){
gulp.src(paths.build.root, { read: false })
.pipe(clean());
});
gulp.task('watch', ['compile'], function(){
gulp.watch([paths.src.dependencies], ['third-party']);
gulp.watch([paths.src.fonts], ['fonts']);
gulp.watch([paths.src.images], ['images']);
gulp.watch([paths.src.appScripts], ['scripts']);
gulp.watch([paths.src.styles], ['styles']);
});
gulp.task('templates', function() {
gulp.src(paths.src.templates)
.pipe(gulp.dest(paths.build.root));
});
gulp.task('scripts', function(){
gulp.src(paths.src.appEntryScript, {read:false})
.pipe($.browserify({
transform: ['coffeeify'],
extensions: ['.coffee']
}))
.pipe($.uglify())
.pipe($.rename('main.js'))
.pipe(gulp.dest(paths.build.browserScriptsRoot));
});
gulp.task('fonts', function(){
gulp.src(paths.src.fonts)
.pipe(gulp.dest(paths.build.fontsRoot));
});
gulp.task('images', function(){
gulp.src(paths.src.images)
.pipe($.imagemin())
.pipe(gulp.dest(paths.build.imagesRoot));
});
gulp.task('styles', function(){
gulp.src(paths.src.styleEntryFile)
.pipe($.less())
.pipe($.minifyCss())
.pipe($.autoprefixer('last 2 versions'))
.pipe($.rename('main.css'))
.pipe(gulp.dest(paths.build.cssRoot));
});
gulp.task('third-party', function(){
gulp.src(paths.src.dependencies)
.pipe($.concat('libs.js'))
.pipe(gulp.dest(paths.build.browserScriptsRoot));
});