Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. const gulp = require("gulp");
  2. const sass = require("gulp-sass");
  3. const browserSync = require("browser-sync").create();
  4. const imagemin = require("gulp-imagemin");
  5. const concat = require("gulp-concat");
  6. const uglify = require("gulp-uglify-es").default;
  7.  
  8. // Compile SCSS into CSS
  9. styles = () => {
  10. return (
  11. gulp
  12. // 1. Where is the SCSS file
  13. .src("./src/scss/APP.scss")
  14.  
  15. // 2. Pass that file through the SASS compiler
  16. .pipe(sass({ outputStyle: "compressed" }).on("error", sass.logError))
  17.  
  18. // 3. Destination for the CSS
  19. .pipe(gulp.dest("./build"))
  20.  
  21. // 4. Stream changes to all browsers
  22. .pipe(browserSync.stream())
  23. );
  24. };
  25.  
  26. html = () => {
  27. return (
  28. gulp
  29. // 1. Where is the HTML file
  30. .src("./src/html/**/*.html")
  31.  
  32. // 2. Destination for the CSS
  33. .pipe(gulp.dest("./build/HTML"))
  34.  
  35. // 3. Stream changes to all browsers
  36. .pipe(browserSync.stream())
  37. );
  38. };
  39.  
  40. javascript = () => {
  41. return (
  42. gulp
  43.  
  44. // 1. Where are the JavaScript dependencies located
  45. .src([
  46. "./node_modules/jquery/dist/jquery.js",
  47. "./src/js/**/*.js",
  48. "./node_modules/bootstrap/dist/js/bootstrap.js"
  49. ])
  50.  
  51. // 2. Bundle and minify the JavaScript
  52. .pipe(concat("bundle.js"))
  53. .pipe(uglify())
  54.  
  55. // 3. Destination for the Javascript
  56. .pipe(gulp.dest("./build"))
  57.  
  58. // 4. Stream changes to all browsers
  59. .pipe(browserSync.stream())
  60. );
  61. };
  62.  
  63. images = () => {
  64. return (
  65. gulp
  66.  
  67. // 1. Where is the images directory
  68. .src("./src/assets/**/*")
  69.  
  70. // 2. Minify the images
  71. .pipe(imagemin())
  72.  
  73. // 3. Destination for the images
  74. .pipe(gulp.dest("./build/images"))
  75.  
  76. // 4. Stream changes to all browsers
  77. .pipe(browserSync.stream())
  78. );
  79. };
  80.  
  81. watch = () => {
  82. browserSync.init({
  83. server: {
  84. baseDir: "./build",
  85. index: "./HTML/index.html"
  86. }
  87. });
  88.  
  89. gulp.watch("./src/html/**/*.html", html);
  90. gulp.watch("./src/scss/**/*.scss", styles);
  91. gulp.watch("./src/js/**/*.js", javascript);
  92. gulp.watch("./src/assets/**/*", images);
  93.  
  94. gulp.watch("./src/js/**/*js").on("change", browserSync.reload);
  95. gulp.watch("./src/html/**/*.html").on("change", browserSync.reload);
  96. gulp.watch("./src/assets/**/*").on("change", browserSync.reload);
  97. };
  98.  
  99. gulp.task("default", gulp.series(html, styles, images, javascript, watch));
  100.  
  101. exports.styles = styles;
  102. exports.watch = watch;
  103. exports.html = html;
  104. exports.javascript = javascript;
  105. exports.images = images;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement