-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
102 lines (82 loc) · 2.45 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
var gulp = require('gulp');
var bowerFiles = require('main-bower-files');
var browserSync = require('browser-sync').create();
var clean = require('gulp-clean');
var concat = require('gulp-concat');
var inject = require('gulp-inject');
var jshint = require('gulp-jshint');
var ngAnnotate = require('gulp-ng-annotate');
var reload = browserSync.reload;
var rename = require('gulp-rename');
var webpack = require('gulp-webpack');
var bases = {
app: 'app/',
dist: 'dist/'
};
var paths = {
css: 'app/**/*.css',
scripts: 'app/**/*.js',
html: 'app/**/*.html',
ttf: 'app/**/*.ttf',
svg: 'app/**/*.svg',
bower_components: 'bower_components/**/*'
};
//Delete the dist directory
gulp.task('clean', function () {
return gulp.src(bases.dist)
.pipe(clean());
});
//Inject our dependencies in index.html
gulp.task('inject', ['copy', 'scripts'], function () {
var target = gulp.src(bases.dist + 'index.html');
var sources = gulp.src(['./dist/' + '**/*.js', bases.dist + '**/*.css']);
return target
.pipe(inject(gulp.src(bowerFiles()), { addRootSlash: false, name: 'bower', relative: false}))
.pipe(inject(sources, {ignorePath: 'dist/', relative: true}))
.pipe(gulp.dest('./dist'))
});
//Process scripts and concatenate them into one output file
gulp.task('scripts', ['clean'], function () {
return gulp.src(paths.scripts)
.pipe(jshint())
.pipe(jshint.reporter())
.pipe(webpack())
.pipe(gulp.dest(bases.dist + 'scripts/'));
});
//Reload browser on file change
gulp.task('browser-reload', ['inject'], function () {
browserSync.reload();
});
//Init browserSync and watch files
gulp.task('serve', ['inject'], function () {
browserSync.init({
startPath: '/',
server: {
baseDir: bases.dist,
routes: {'/bower_components': 'bower_components'}
}
});
gulp.watch(bases.app + '**/*.js', ['browser-reload']);
gulp.watch(bases.app + '**/*.css', ['browser-reload']);
gulp.watch(bases.app + '**/*.html', ['browser-reload']);
});
//Copy all other files to dist directly
gulp.task('copy', ['clean'], function () {
gulp.src('bower.json')
.pipe(gulp.dest(bases.dist));
gulp.src(paths.bower_components)
.pipe(gulp.dest(bases.dist + 'bower_components'));
//Copy html
gulp.src(paths.html)
.pipe(gulp.dest(bases.dist));
//Copy css
gulp.src(paths.css)
.pipe(gulp.dest(bases.dist));
//Copy fonts
gulp.src(paths.ttf)
.pipe(gulp.dest(bases.dist));
//Copy loader
gulp.src(paths.svg)
.pipe(gulp.dest(bases.dist));
});
gulp.task('default', ['serve', 'browser-reload']);