|
| 1 | +"use strict"; |
| 2 | + |
1 | 3 | // Load plugins |
2 | 4 | const browsersync = require("browser-sync").create(); |
| 5 | +const del = require("del"); |
3 | 6 | const gulp = require("gulp"); |
4 | | - |
5 | | -// Copy third party libraries from /node_modules into /vendor |
6 | | -gulp.task('vendor', function(cb) { |
7 | | - |
8 | | - // Bootstrap |
9 | | - gulp.src([ |
10 | | - './node_modules/bootstrap/dist/**/*', |
11 | | - '!./node_modules/bootstrap/dist/css/bootstrap-grid*', |
12 | | - '!./node_modules/bootstrap/dist/css/bootstrap-reboot*' |
13 | | - ]) |
14 | | - .pipe(gulp.dest('./vendor/bootstrap')) |
15 | | - |
16 | | - // jQuery |
17 | | - gulp.src([ |
18 | | - './node_modules/jquery/dist/*', |
19 | | - '!./node_modules/jquery/dist/core.js' |
20 | | - ]) |
21 | | - .pipe(gulp.dest('./vendor/jquery')) |
22 | | - |
23 | | - // jQuery Easing |
24 | | - gulp.src([ |
25 | | - 'node_modules/jquery.easing/*.js' |
26 | | - ]) |
27 | | - .pipe(gulp.dest('vendor/jquery-easing')) |
28 | | - |
29 | | - cb(); |
30 | | - |
31 | | -}); |
| 7 | +const merge = require("merge-stream"); |
32 | 8 |
|
33 | 9 | // BrowserSync |
34 | 10 | function browserSync(done) { |
35 | 11 | browsersync.init({ |
36 | 12 | server: { |
37 | 13 | baseDir: "./" |
38 | | - } |
| 14 | + }, |
| 15 | + port: 3000 |
39 | 16 | }); |
40 | 17 | done(); |
41 | 18 | } |
42 | 19 |
|
43 | | -// BrowserSync Reload |
| 20 | +// BrowserSync reload |
44 | 21 | function browserSyncReload(done) { |
45 | 22 | browsersync.reload(); |
46 | 23 | done(); |
47 | 24 | } |
48 | 25 |
|
| 26 | +// Clean vendor |
| 27 | +function clean() { |
| 28 | + return del(["./vendor/"]); |
| 29 | +} |
| 30 | + |
| 31 | +// Bring third party dependencies from node_modules into vendor directory |
| 32 | +function modules() { |
| 33 | + // Bootstrap |
| 34 | + var bootstrap = gulp.src('./node_modules/bootstrap/dist/**/*') |
| 35 | + .pipe(gulp.dest('./vendor/bootstrap')); |
| 36 | + // jQuery |
| 37 | + var jquery = gulp.src([ |
| 38 | + './node_modules/jquery/dist/*', |
| 39 | + '!./node_modules/jquery/dist/core.js' |
| 40 | + ]) |
| 41 | + .pipe(gulp.dest('./vendor/jquery')); |
| 42 | + // jQuery Easing |
| 43 | + var jqueryEasing = gulp.src('./node_modules/jquery.easing/*.js') |
| 44 | + .pipe(gulp.dest('./vendor/jquery-easing')); |
| 45 | + return merge(bootstrap, jquery, jqueryEasing); |
| 46 | +} |
| 47 | + |
49 | 48 | // Watch files |
50 | 49 | function watchFiles() { |
51 | | - gulp.watch("./css/*", browserSyncReload); |
| 50 | + gulp.watch("./**/*.css", browserSyncReload); |
52 | 51 | gulp.watch("./**/*.html", browserSyncReload); |
53 | 52 | } |
54 | 53 |
|
55 | | -gulp.task("default", gulp.parallel('vendor')); |
| 54 | +// Define complex tasks |
| 55 | +const vendor = gulp.series(clean, modules); |
| 56 | +const build = gulp.series(vendor); |
| 57 | +const watch = gulp.series(build, gulp.parallel(watchFiles, browserSync)); |
56 | 58 |
|
57 | | -// dev task |
58 | | -gulp.task("dev", gulp.parallel(watchFiles, browserSync)); |
| 59 | +// Export tasks |
| 60 | +exports.clean = clean; |
| 61 | +exports.vendor = vendor; |
| 62 | +exports.build = build; |
| 63 | +exports.watch = watch; |
| 64 | +exports.default = build; |
0 commit comments