-
Notifications
You must be signed in to change notification settings - Fork 9
/
gulpfile.js
66 lines (58 loc) · 2.08 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
var gulp = require('gulp');
var sass = require('gulp-sass');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var concat = require('gulp-concat');
var htmlmin = require('gulp-htmlmin');
var plumber = require('gulp-plumber');
var autoprefixer = require('gulp-autoprefixer');
var cleanCSS = require('gulp-clean-css');
var sourcemaps = require('gulp-sourcemaps');
var open = require('gulp-open');
var config = {
sourceDir: './src/',
publicDir: './dist/'
};
/* Scripts task */
gulp.task('scripts', function () {
return gulp.src([config.sourceDir + 'js/perfomance.js', config.sourceDir + 'js/data-generator.js', config.sourceDir + 'js/index.js'])
.pipe(concat('app.js'))
.pipe(gulp.dest(config.sourceDir))
.pipe(uglify())
.pipe(gulp.dest(config.publicDir));
});
/* Styles task */
gulp.task('styles', function () {
return gulp.src(config.sourceDir + '/sass/app.scss')
.pipe(sass().on('error', sass.logError))
.pipe(sourcemaps.write('.'))
.pipe(autoprefixer())
.pipe(gulp.dest(config.sourceDir))
.pipe(cleanCSS())
.pipe(gulp.dest(config.publicDir))
});
/* HTML min */
gulp.task('minifyHtml', function () {
return gulp.src(config.sourceDir + 'index.html')
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest(config.publicDir));
});
// Open file with default application
gulp.task('openSrc', function(){
gulp.src('./src/index.html')
.pipe(open());
});
// Open file with default application
gulp.task('openDist', function(){
gulp.src('./dist/index.min.html')
.pipe(open());
});
/* Watch scss, js and html files, doing different things with each. */
gulp.task('default', ['scripts', 'styles', 'openSrc', 'minifyHtml'], function () {
/* Watch scss, run the sass task on change. */
gulp.watch(config.sourceDir + 'sass/**/*.*', ['styles']);
/* Watch app.js file, run the scripts task on change. */
gulp.watch(config.sourceDir + 'js/**/*.*', ['scripts']);
});
/* Production */
gulp.task('prod', ['scripts', 'styles', 'minifyHtml', 'openDist']);