-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
89 lines (72 loc) · 2.17 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
const gulp = require('gulp');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const browserify = require('browserify');
const babel = require('babelify');
const uglify = require('gulp-uglify');
const sourcemaps = require("gulp-sourcemaps");
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const importCSS = require('postcss-import');
const svgstore = require("gulp-svgstore");
const inject = require("gulp-inject")
const browserSync = require('browser-sync');
const path = require('path');
gulp.task('javascript', () => {
const bundler = browserify('./index.js', {debug: true})
.transform(babel, {
presets: ['es2015']
});
return bundler.bundle()
.on('error', function(err) {
console.error(err);
this.emit('end')
})
.pipe(source('app.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(uglify())
.pipe(sourcemaps.write())
.pipe(gulp.dest('./build'));
});
function css() {
var processors = [
importCSS(),
autoprefixer()
];
return gulp.src("index.css")
.pipe(sourcemaps.init())
.pipe(postcss(processors))
.pipe(sourcemaps.write())
.on('error', function(err) {
console.error(err);
this.emit('end');
})
.pipe(gulp.dest('./build'));
}
gulp.task('css', css);
gulp.task('synccss', () => {
return css().pipe(browserSync.stream());
})
gulp.task('browserSync-js', ['javascript'], () => {
browserSync.reload();
});
gulp.task('assets', () => {
gulp.src("./assets/*")
.pipe(gulp.dest("./build/assets/"));
})
gulp.task('default', ['javascript', 'css', 'assets']);
gulp.task('serve', ['default'], () => {
browserSync.init({
server: {
baseDir: "./build"
},
ghostMode: false,
port: 8082
});
gulp.watch("./index.js", ['browserSync-js']);
gulp.watch("./lib/*.js", ['browserSync-js']);
gulp.watch("./index.css", ['synccss']);
gulp.watch("./style/*.css", ['synccss']);
gulp.watch("./assets/*", ['assets']);
})