-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
91 lines (80 loc) · 2.68 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
const gulp = require('gulp'),
connect = require('gulp-connect'), //opens dev server
open = require('gulp-open'), //opens the web browser
browserify = require('browserify'),
babelify = require('babelify'),
source = require('vinyl-source-stream'), //Use conventional text streams with Gulp
concat = require('gulp-concat'),
lint = require('gulp-eslint')
friendlyFormatter = require('eslint-friendly-formatter'); //export EFF_NO_GRAY=true in console if you can't see the output
const config = {
port: 9000,
devBaseUrl: 'http://localhost',
paths: {
html: './src/*.html',
js: './src/**/*.js',
css: [
'node_modules/bootstrap/dist/css/bootstrap.min.css',
'node_modules/bootstrap/dist/css/bootstrap-theme.min.css',
'node_modules/toastr/toastr.css'
],
dist: './dist',
images: './src/images/*',
mainJs: './src/main.js'
}
};
gulp.task('connect', () => {
connect.server({
root: ['dist'],
port: config.port,
base: config.devBaseUrl,
livereload: true
});
});
gulp.task('open', ['connect'], () => {
gulp.src('dist/index.html')
.pipe(open({
uri: config.devBaseUrl + ':' + config.port + '/'
}))
});
gulp.task('images', () => {
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('html', () => {
gulp.src(config.paths.html)
.pipe(gulp.dest(config.paths.dist))
.pipe(connect.reload());
});
gulp.task('js', () => {
browserify(config.paths.mainJs, {debug: true})
.transform(babelify,{
presets: ["es2015", "react"],
plugins: ["syntax-class-properties", "transform-class-properties"],
sourceMaps: true
})
.bundle()
.on('error', console.error.bind(console))
.pipe(source('bundle.js'))
.pipe(gulp.dest(config.paths.dist + '/scripts'))
.pipe(connect.reload());
});
gulp.task('css', () => {
gulp.src(config.paths.css)
.pipe(concat('bundle.css'))
.pipe(gulp.dest(config.paths.dist + '/css'));
});
gulp.task('lint', () => {
return gulp.src(config.paths.js)
.pipe(lint({config: 'eslint.config.json'}))
.pipe(lint.format(friendlyFormatter));
});
gulp.task('watch', () => {
gulp.watch(config.paths.html, ['html']);
gulp.watch(config.paths.js, ['js', 'lint']);
gulp.watch(config.paths.images, ['images']);
});
gulp.task('default', ['html', 'js', 'css', 'lint', 'images', 'open', 'watch']);