-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
100 lines (87 loc) · 2.53 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
// gulp tasks
import gulp from 'gulp';
import sourcemaps from 'gulp-sourcemaps'
import plumber from 'gulp-plumber'
import concat from 'gulp-concat';
import uglify from 'gulp-uglify';
import rename from 'gulp-rename';
import notify from 'gulp-notify';
// js
import jshint from 'gulp-jshint';
import babel from 'gulp-babel';
// css
import sass from 'gulp-sass';
import minifyCSS from 'gulp-clean-css';
import autoprefixer from 'gulp-autoprefixer';
// images
import imageMin from 'gulp-imagemin'
// server
const browserSync = require('browser-sync').create();
const reload = browserSync.reload;
const paths = {
styles: {
src: 'src/styles/**/*.scss',
dest: 'public/styles'
},
scripts: {
src: 'src/scripts/**/*.js',
dest: 'public/scripts'
},
assets: {
src: 'src/assets/**/*',
dest: 'public/assets'
}
};
/*
* For small tasks you can export arrow functions
*/
const startServer = () => browserSync.init({ server: './' })
/*
* You can also declare named functions and export them as tasks
*/
export function styles() {
return gulp.src(paths.styles.src, { sourcemaps: true })
.pipe(plumber({
errorHandler: notify.onError("Error: <%= error.message %>")
}))
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(minifyCSS())
.pipe(autoprefixer('last 5 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1'))
.pipe(sourcemaps.write('.'))
.pipe(concat('style.min.css'))
// .pipe(rename({
// basename: 'style',
// suffix: '.min'
// }))
.pipe(gulp.dest(paths.styles.dest))
.pipe(reload({ stream: true }));
}
export function scripts() {
return gulp.src(paths.scripts.src, { sourcemaps: true })
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'))
.pipe(babel())
.pipe(uglify())
.pipe(concat('main.min.js'))
.pipe(gulp.dest(paths.scripts.dest))
.pipe(reload({ stream: true }));
}
export function assets() {
return gulp.src(paths.assets.src)
.pipe(imageMin())
.pipe(gulp.dest('public/assets'));
}
function watch() {
gulp.watch(paths.scripts.src, scripts);
gulp.watch(paths.styles.src, styles);
gulp.watch('*.html', reload)
}
const serve = gulp.series(gulp.parallel(styles, scripts, assets), startServer);
const start = gulp.parallel(serve, watch)
const build = gulp.parallel(styles, scripts, assets)
export { build }
/*
* Export a default task
*/
export default start;