-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
56 lines (47 loc) · 1.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
var gulp = require('gulp');
var sass = require('gulp-sass');
var browserSync = require('browser-sync');
var useref = require('gulp-useref');
var uglify = require('gulp-uglify');
var gulpIf = require('gulp-if');
var minifyCss = require('gulp-clean-css');
var inject = require('gulp-inject');
var concat = require('gulp-concat');
gulp.task('index', function () {
var target = gulp.src('app/index.html');
// It's not necessary to read the files (will speed up things), we're only after their paths:
var sources = gulp.src(['./app/**/*.module.js','./app/**/*.js', 'app/**/*.css'], {read: false});
return target.pipe(inject(sources, {ignorePath: '/app/', addRootSlash: false}))
.pipe(gulp.dest('app'));
});
gulp.task('sass', function(){
return gulp.src('app/**/*.scss')
.pipe(sass())
.pipe(gulp.dest('app/css'))
.pipe(browserSync.stream());
});
gulp.task('browserSync', function () {
browserSync({
server: {
baseDir: 'app'
}
})
});
gulp.task('scripts', function() {
return gulp.src(['./app/**/*.module.js','./app/**/*.js'])
.pipe(concat('main.js'))
.pipe(gulp.dest('app'));
});
gulp.task('useref', function () {
return gulp.src('app/*.html')
.pipe(useref())
.pipe(gulpIf('**/*.js', uglify()))
.pipe(gulpIf('**/*.css', minifyCss()))
.pipe(gulp.dest('dist'))
});
gulp.task('serve', ['index', 'browserSync', 'sass'], function(){
gulp.watch('app/**/*.scss', ['sass']);
// Reloads the browser whenever html or js files change
gulp.watch('app/**/*.html').on('change',browserSync.reload);
gulp.watch('app/**/*.js').on('change',browserSync.reload);
});