|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +// Load plugins |
| 4 | +const autoprefixer = require("gulp-autoprefixer"); |
| 5 | +const browsersync = require("browser-sync").create(); |
| 6 | +const cleanCSS = require("gulp-clean-css"); |
| 7 | +const del = require("del"); |
| 8 | +const gulp = require("gulp"); |
| 9 | +const header = require("gulp-header"); |
| 10 | +const merge = require("merge-stream"); |
| 11 | +const plumber = require("gulp-plumber"); |
| 12 | +const rename = require("gulp-rename"); |
| 13 | +const sass = require("gulp-sass"); |
| 14 | +const uglify = require("gulp-uglify"); |
| 15 | + |
| 16 | +// Load package.json for banner |
| 17 | +const pkg = require('./package.json'); |
| 18 | + |
| 19 | +// Set the banner content |
| 20 | +const banner = ['/*!\n', |
| 21 | + ' * Start Bootstrap - <%= pkg.title %> v<%= pkg.version %> (<%= pkg.homepage %>)\n', |
| 22 | + ' * Copyright 2013-' + (new Date()).getFullYear(), ' <%= pkg.author %>\n', |
| 23 | + ' * Licensed under <%= pkg.license %> (https://github.com/BlackrockDigital/<%= pkg.name %>/blob/master/LICENSE)\n', |
| 24 | + ' */\n', |
| 25 | + '\n' |
| 26 | +].join(''); |
| 27 | + |
| 28 | +// BrowserSync |
| 29 | +function browserSync(done) { |
| 30 | + browsersync.init({ |
| 31 | + server: { |
| 32 | + baseDir: "./" |
| 33 | + }, |
| 34 | + port: 3000 |
| 35 | + }); |
| 36 | + done(); |
| 37 | +} |
| 38 | + |
| 39 | +// BrowserSync reload |
| 40 | +function browserSyncReload(done) { |
| 41 | + browsersync.reload(); |
| 42 | + done(); |
| 43 | +} |
| 44 | + |
| 45 | +// Clean vendor |
| 46 | +function clean() { |
| 47 | + return del(["./vendor/"]); |
| 48 | +} |
| 49 | + |
| 50 | +// Bring third party dependencies from node_modules into vendor directory |
| 51 | +function modules() { |
| 52 | + // Bootstrap |
| 53 | + var bootstrap = gulp.src('./node_modules/bootstrap/dist/**/*') |
| 54 | + .pipe(gulp.dest('./vendor/bootstrap')); |
| 55 | + // Font Awesome CSS |
| 56 | + var fontAwesomeCSS = gulp.src('./node_modules/@fortawesome/fontawesome-free/css/**/*') |
| 57 | + .pipe(gulp.dest('./vendor/fontawesome-free/css')); |
| 58 | + // Font Awesome Webfonts |
| 59 | + var fontAwesomeWebfonts = gulp.src('./node_modules/@fortawesome/fontawesome-free/webfonts/**/*') |
| 60 | + .pipe(gulp.dest('./vendor/fontawesome-free/webfonts')); |
| 61 | + // jQuery Easing |
| 62 | + var jqueryEasing = gulp.src('./node_modules/jquery.easing/*.js') |
| 63 | + .pipe(gulp.dest('./vendor/jquery-easing')); |
| 64 | + // jQuery |
| 65 | + var jquery = gulp.src([ |
| 66 | + './node_modules/jquery/dist/*', |
| 67 | + '!./node_modules/jquery/dist/core.js' |
| 68 | + ]) |
| 69 | + .pipe(gulp.dest('./vendor/jquery')); |
| 70 | + return merge(bootstrap, fontAwesomeCSS, fontAwesomeWebfonts, jquery, jqueryEasing); |
| 71 | +} |
| 72 | + |
| 73 | +// CSS task |
| 74 | +function css() { |
| 75 | + return gulp |
| 76 | + .src("./scss/**/*.scss") |
| 77 | + .pipe(plumber()) |
| 78 | + .pipe(sass({ |
| 79 | + outputStyle: "expanded", |
| 80 | + includePaths: "./node_modules", |
| 81 | + })) |
| 82 | + .on("error", sass.logError) |
| 83 | + .pipe(autoprefixer({ |
| 84 | + browsers: ['last 2 versions'], |
| 85 | + cascade: false |
| 86 | + })) |
| 87 | + .pipe(header(banner, { |
| 88 | + pkg: pkg |
| 89 | + })) |
| 90 | + .pipe(gulp.dest("./css")) |
| 91 | + .pipe(rename({ |
| 92 | + suffix: ".min" |
| 93 | + })) |
| 94 | + .pipe(cleanCSS()) |
| 95 | + .pipe(gulp.dest("./css")) |
| 96 | + .pipe(browsersync.stream()); |
| 97 | +} |
| 98 | + |
| 99 | +// JS task |
| 100 | +function js() { |
| 101 | + return gulp |
| 102 | + .src([ |
| 103 | + './js/*.js', |
| 104 | + '!./js/*.min.js', |
| 105 | + '!./js/contact_me.js', |
| 106 | + '!./js/jqBootstrapValidation.js' |
| 107 | + ]) |
| 108 | + .pipe(uglify()) |
| 109 | + .pipe(header(banner, { |
| 110 | + pkg: pkg |
| 111 | + })) |
| 112 | + .pipe(rename({ |
| 113 | + suffix: '.min' |
| 114 | + })) |
| 115 | + .pipe(gulp.dest('./js')) |
| 116 | + .pipe(browsersync.stream()); |
| 117 | +} |
| 118 | + |
| 119 | +// Watch files |
| 120 | +function watchFiles() { |
| 121 | + gulp.watch("./scss/**/*", css); |
| 122 | + gulp.watch(["./js/**/*", "!./js/**/*.min.js"], js); |
| 123 | + gulp.watch("./**/*.html", browserSyncReload); |
| 124 | +} |
| 125 | + |
| 126 | +// Define complex tasks |
| 127 | +const vendor = gulp.series(clean, modules); |
| 128 | +const build = gulp.series(vendor, gulp.parallel(css, js)); |
| 129 | +const watch = gulp.series(build, gulp.parallel(watchFiles, browserSync)); |
| 130 | + |
| 131 | +// Export tasks |
| 132 | +exports.css = css; |
| 133 | +exports.js = js; |
| 134 | +exports.clean = clean; |
| 135 | +exports.vendor = vendor; |
| 136 | +exports.build = build; |
| 137 | +exports.watch = watch; |
| 138 | +exports.default = build; |
0 commit comments