-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.babel.js
121 lines (96 loc) · 2.73 KB
/
gulpfile.babel.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
'use strict';
import gulp from 'gulp';
import sourcemaps from 'gulp-sourcemaps';
import clean from 'gulp-clean';
import concat from 'gulp-concat';
import merge from 'merge-stream';
import postcss from 'gulp-postcss';
import precss from 'precss';
import autoprefixer from 'autoprefixer';
import cssnano from 'cssnano';
import browserify from 'browserify';
import babelify from 'babelify';
import source from 'vinyl-source-stream';
import buffer from 'vinyl-buffer';
import uglify from 'gulp-uglify';
import eslint from 'gulp-eslint';
let browsersync = require('browser-sync').create();
const dest = 'dist';
gulp.task('css', () => {
let processors = [
precss(),
autoprefixer(),
cssnano()
];
const files = ['app', 'float'];
let tasks = files.map((entry) => {
return gulp.src('css/' + entry + '.css')
.pipe(sourcemaps.init())
.pipe(postcss(processors))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(dest))
.pipe(browsersync.stream({match: '**/*.css'}));
});
return merge(tasks);
});
gulp.task('test-js', () => {
const options = {
parserOptions: {
ecmaVersion: 6,
sourceType: 'module'
},
extends: 'eslint:recommended',
rules: {
'quotes': ['error', 'single'],
'linebreak-style': ['error', 'unix'],
'eqeqeq': ['warn', 'always'],
'indent': ['error', 'tab']
}
};
return gulp.src(['*.js', 'js/**/*.js'])
.pipe(eslint(options))
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('js', gulp.series('test-js', () => {
const files = ['twos', 'float', 'floatconv', 'hexconv'];
const babel_options = {presets: ['@babel/preset-env'], sourceMaps: true};
let tasks = files.map((entry) => {
entry += '.js';
return browserify({entries: 'js/' + entry, debug: true})
.transform(babelify, babel_options)
.bundle()
.pipe(source(entry))
.pipe(buffer())
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(dest))
.pipe(browsersync.stream({match: '**/*.js'}));
});
tasks.push(gulp.src(['node_modules/angular/angular.js','node_modules/angular-sanitize/angular-sanitize.js'])
.pipe(concat('angular.js'))
.pipe(uglify())
.pipe(gulp.dest(dest)));
return merge(tasks);
}));
gulp.task('clean', () => {
return gulp.src(dest, {read: false, allowEmpty: true})
.pipe(clean());
});
gulp.task('test', gulp.parallel('test-js'));
gulp.task('default', gulp.series('clean', gulp.parallel('css', 'js')));
gulp.task('watch', gulp.series('default', (done) => {
gulp.watch('css/**/*.css', gulp.series('css'));
gulp.watch('js/**/*.js', gulp.series('js'));
done();
}));
gulp.task('browsersync', gulp.series('watch', (done) => {
browsersync.init({
server: {
baseDir: './'
}
});
gulp.watch('*.html').on('change', browsersync.reload);
done();
}));