-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
101 lines (88 loc) · 2.95 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
'use strict'
var gulp = require('gulp'),
mocha = require('gulp-mocha'),
gutil = require('gulp-util'),
connect = require('gulp-connect'), // runs a webserver
open = require('gulp-open'), // opens a url in a browser
browserify = require('browserify'),
reactify = require('reactify'), // transform JSX to JS
source = require('vinyl-source-stream'), // use conventional text streams with Gulp
lint = require('gulp-eslint'),
concat = require('gulp-concat'),
neat = require('node-neat'),
sass = require('gulp-sass');
var config = {
port: 9005,
baseDevUrl: 'http://localhost',
paths: {
//css: ['./src/style.css'],
js: './src/**/*.js',
test: './test/*.js',
html: './src/*.html',
images: '.src/images/*',
dist: './dist',
mainJs: './src/main.js',
sass: {
src: './src/styles/sass/**/*.{sass,scss}',
settings: {
includePaths: neat.includePaths
//,style: 'compressed',
//quiet: true
}
}
}
};
gulp.task('connect', function(){
connect.server({
root: ['dist'],
port: config.port,
base: config.baseDevUrl,
livereload: true
});
});
gulp.task('open', ['connect'], function(){
gulp.src('dist/index.html').pipe(open({uri: config.baseDevUrl + ':' + config.port + '/'}));
});
gulp.task('html', function(){
gulp.src(config.paths.html).pipe(gulp.dest(config.paths.dist)).pipe(connect.reload());
});
gulp.task('images', function(){
gulp.src(config.paths.images).pipe(gulp.dest(config.paths.dist + '/images')).pipe(connect.reload());
//gulp.src('.src/favicon.ico').pipe(gulp.dest(config.paths.dist));
});
gulp.task('mocha', function(){
return gulp.src(
[config.paths.test],
{read:false}).pipe(mocha({reporter:'list'})).on('error', gutil.log);
});
gulp.task('js', function(){
browserify(config.paths.mainJs)
.transform(reactify)
.bundle()
.on('error', console.error.bind(console))
.pipe(source('bundle.js'))
.pipe(gulp.dest(config.paths.dist + '/scripts'))
.pipe(connect.reload());
});
// gulp.task('css', function(){
// gulp.src(config.paths.css).pipe(concat('bundle.css')).pipe(gulp.dest(config.paths.dist + '/css'));
// });
gulp.task('sass', function(){
return gulp.src(config.paths.sass.src)
.pipe(sass(config.paths.sass.settings))
.pipe(gulp.dest(config.paths.dist + '/css'))
});
gulp.task('watch', function(){
gulp.run('mocha'); // run the 'mocha' task on initial invocation of this task
gulp.watch([config.paths.js, config.paths.test], ['mocha']); // setup a file watcher, which will run the 'mocha' task as files change
gulp.watch([config.paths.html], ['html']);
gulp.watch([config.paths.js], ['js','lint']);
// gulp.watch(config.paths.css, ['css']);
gulp.watch([config.paths.sass.src], ['sass']);
});
gulp.task('lint', function(){
gulp.src(config.paths.js)
.pipe(lint({config: 'eslint.config.json'}))
.pipe(lint.format());
});
gulp.task('default', ['watch', 'html', 'js', 'sass', 'lint', 'open']); // set the default task(s)