Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.54 KB | None | 0 0
  1. "use strict";
  2.  
  3. const { src, dest } = require("gulp");
  4. const gulp = require("gulp");
  5. const autoprefixer = require("gulp-autoprefixer");
  6. const cssbeautify = require("gulp-cssbeautify");
  7. const removeComments = require('gulp-strip-css-comments');
  8. const rename = require("gulp-rename");
  9. const sass = require("gulp-sass");
  10. const cssnano = require("gulp-cssnano");
  11. const rigger = require("gulp-rigger");
  12. const uglify = require("gulp-uglify");
  13. const plumber = require("gulp-plumber");
  14. const imagemin = require("gulp-imagemin");
  15. const del = require("del");
  16. const panini = require("panini");
  17. const browsersync = require("browser-sync").create();
  18.  
  19.  
  20.  
  21. /* Paths to source/build/watch files
  22. =========================*/
  23.  
  24. var path = {
  25. build: {
  26. html: "dist/",
  27. js: "dist/assets/js/",
  28. css: "dist/assets/css/",
  29. images: "dist/assets/i/"
  30. },
  31. src: {
  32. html: "src/*.{htm,html,php}",
  33. js: "src/assets/js/*.js",
  34. css: "src/assets/sass/style.scss",
  35. images: "src/assets/i/**/*.{jpg,png,svg,gif,ico}"
  36. },
  37. watch: {
  38. html: "src/**/*.{htm,html,php}",
  39. js: "src/assets/js/**/*.js",
  40. css: "src/assets/sass/**/*.scss",
  41. images: "src/assets/i/**/*.{jpg,png,svg,gif,ico}"
  42. },
  43. clean: "./dist"
  44. };
  45.  
  46.  
  47. /* Tasks
  48. =========================*/
  49.  
  50. function browserSync(done) {
  51. browsersync.init({
  52. server: {
  53. baseDir: "./dist/"
  54. },
  55. port: 3000
  56. });
  57. done();
  58. }
  59.  
  60. function browserSyncReload(done) {
  61. browsersync.reload();
  62. done();
  63. }
  64.  
  65. function html() {
  66. panini.refresh();
  67. return src(path.src.html, { base: 'src/' })
  68. .pipe(plumber())
  69. .pipe(panini({
  70. root: 'src/',
  71. layouts: 'src/tpl/layouts/',
  72. partials: 'src/tpl/partials/',
  73. helpers: 'src/tpl/helpers/',
  74. data: 'src/tpl/data/'
  75. }))
  76. .pipe(dest(path.build.html))
  77. .pipe(browsersync.stream());
  78. }
  79.  
  80. function css() {
  81. return src(path.src.css, { base: './src/assets/sass/' })
  82. .pipe(plumber())
  83. .pipe(sass().on('error', sass.logError))
  84. .pipe(autoprefixer({
  85. browsers: ["last 8 versions"],
  86. cascade: true
  87. }))
  88. .pipe(cssbeautify())
  89. .pipe(dest(path.build.css))
  90. .pipe(cssnano({
  91. zindex: false,
  92. discardComments: {
  93. removeAll: true
  94. }
  95. }))
  96. .pipe(removeComments())
  97. .pipe(rename({
  98. suffix: ".min",
  99. extname: ".css"
  100. }))
  101. .pipe(dest(path.build.css))
  102. .pipe(browsersync.stream());
  103. }
  104.  
  105. function js() {
  106. return src(path.src.js, { base: './src/assets/js/' })
  107. .pipe(plumber())
  108. .pipe(rigger())
  109. .pipe(gulp.dest(path.build.js))
  110. .pipe(uglify())
  111. .pipe(rename({
  112. suffix: ".min",
  113. extname: ".js"
  114. }))
  115. .pipe(dest(path.build.js))
  116. .pipe(browsersync.stream());
  117. }
  118.  
  119. function images() {
  120. return src(path.src.images)
  121. .pipe(dest(path.build.images));
  122. }
  123.  
  124. function clean() {
  125. return del(path.clean);
  126. }
  127.  
  128. function watchFiles() {
  129. gulp.watch([path.watch.html], html);
  130. gulp.watch([path.watch.css], css);
  131. gulp.watch([path.watch.js], js);
  132. gulp.watch([path.watch.images], images);
  133. }
  134.  
  135. const build = gulp.series(clean, gulp.parallel(html, css, js, images));
  136. const watch = gulp.parallel(build, watchFiles, browserSync);
  137.  
  138.  
  139. // export tasks
  140. exports.html = html;
  141. exports.css = css;
  142. exports.js = js;
  143. exports.images = images;
  144. exports.clean = clean;
  145. exports.build = build;
  146. exports.watch = watch;
  147. exports.default = watch;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement