1
|
|
|
import gulp from 'gulp'; |
2
|
|
|
import browserSync from 'browser-sync'; |
3
|
|
|
import rename from 'gulp-rename'; |
4
|
|
|
import sass from 'gulp-sass'; |
5
|
|
|
import postcss from 'gulp-postcss'; |
6
|
|
|
import cssnano from 'cssnano'; |
7
|
|
|
import autoprefixer from 'autoprefixer'; |
8
|
|
|
import eslint from 'gulp-eslint'; |
9
|
|
|
import sasslint from 'gulp-sass-lint'; |
10
|
|
|
import browserify from 'browserify'; |
11
|
|
|
import babelify from 'babelify'; |
12
|
|
|
import source from 'vinyl-source-stream'; |
13
|
|
|
import streamify from 'gulp-streamify'; |
14
|
|
|
import uglify from 'gulp-uglify'; |
15
|
|
|
|
16
|
|
|
const server = browserSync.create(); |
17
|
|
|
|
18
|
|
|
const styles = () => { |
19
|
|
|
const plugins = [autoprefixer(), cssnano()]; |
20
|
|
|
|
21
|
|
|
return ( |
22
|
|
|
gulp.src(['./src/scss/main.scss', './src/scss/theme.scss']) |
23
|
|
|
.pipe(sass().on('error', sass.logError)) |
24
|
|
|
.pipe(gulp.dest('./dist/css')) |
25
|
|
|
.pipe(postcss(plugins)) |
26
|
|
|
.pipe(rename({ suffix: '.min' })) |
27
|
|
|
.pipe(gulp.dest('./dist/css')) |
28
|
|
|
.pipe(server.stream()) |
29
|
|
|
); |
30
|
|
|
}; |
31
|
|
|
|
32
|
|
|
const scripts = () => browserify({ |
33
|
|
|
entries: './index.js', |
34
|
|
|
standalone: 'FunnelGraph' |
35
|
|
|
}).transform(babelify, { presets: ['@babel/preset-env'] }) |
36
|
|
|
.bundle() |
37
|
|
|
.pipe(source('funnel-graph.js')) |
38
|
|
|
.pipe(gulp.dest('dist/js')) |
39
|
|
|
.pipe(streamify(uglify())) |
40
|
|
|
.pipe(rename({ suffix: '.min' })) |
41
|
|
|
.pipe(gulp.dest('dist/js')) |
42
|
|
|
.pipe(server.stream()); |
43
|
|
|
|
44
|
|
|
const scriptsLint = () => gulp.src('./src/js/*.js') |
45
|
|
|
.pipe(eslint()) |
46
|
|
|
.pipe(eslint.format()); |
47
|
|
|
|
48
|
|
|
const stylesLint = () => gulp.src('./src/scss/**/*.scss') |
49
|
|
|
.pipe(sasslint()) |
50
|
|
|
.pipe(sasslint.format()); |
51
|
|
|
|
52
|
|
|
const startServer = () => server.init({ |
53
|
|
|
server: { |
54
|
|
|
baseDir: './' |
55
|
|
|
} |
56
|
|
|
}); |
57
|
|
|
|
58
|
|
|
const watchHTML = () => gulp.watch('./*.html').on('change', server.reload); |
59
|
|
|
const watchScripts = () => gulp.watch('./src/js/*.js', gulp.series('scriptsLint', 'scripts')); |
60
|
|
|
const watchStyles = () => gulp.watch('./src/scss/**/*.scss', gulp.series('stylesLint', 'styles')); |
61
|
|
|
|
62
|
|
|
const compile = gulp.parallel(styles, scripts); |
63
|
|
|
const lint = gulp.parallel(scriptsLint, stylesLint); |
64
|
|
|
const serve = gulp.series(compile, startServer); |
65
|
|
|
const watch = gulp.series(lint, gulp.parallel(watchHTML, watchScripts, watchStyles)); |
66
|
|
|
const defaultTasks = gulp.parallel(serve, watch); |
67
|
|
|
|
68
|
|
|
export { |
69
|
|
|
styles, |
70
|
|
|
scripts, |
71
|
|
|
scriptsLint, |
72
|
|
|
stylesLint, |
73
|
|
|
watchHTML, |
74
|
|
|
watchScripts, |
75
|
|
|
watchStyles, |
76
|
|
|
startServer, |
77
|
|
|
serve, |
78
|
|
|
watch, |
79
|
|
|
compile, |
80
|
|
|
lint |
81
|
|
|
}; |
82
|
|
|
|
83
|
|
|
export default defaultTasks; |
84
|
|
|
|