Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.49 KB | None | 0 0
  1. /* global require */
  2. var gulp = require("gulp"),
  3. browserSync = require("browser-sync").create(),
  4. del = require("del"),
  5. gutil = require("gulp-util"),
  6. minifyCss = require("gulp-minify-css"),
  7. concatCss = require("gulp-concat-css"),
  8. rename = require("gulp-rename"),
  9. gulpif = require("gulp-if"),
  10. uglify = require("gulp-uglify"),
  11. imagemin = require("gulp-imagemin"),
  12. autoprefixer = require("gulp-autoprefixer"),
  13. filter = require("gulp-filter"),
  14. ftp = require("vinyl-ftp"),
  15. wiredep = require("wiredep").stream,
  16. useref = require("gulp-useref"),
  17. size = require("gulp-size");
  18.  
  19. /*******************************************
  20. * APP
  21. ******************************************/
  22. // Запускаем локальный сервер
  23. gulp.task("server", function () {
  24. browserSync.init({
  25. notify: false,
  26. port: 1000,
  27. server: { baseDir: "./app" }
  28. });
  29. });
  30.  
  31. // Подключаем Bower файлы
  32. gulp.task("wiredep-bower", function () {
  33. return gulp.src("./app/*.html")
  34. .pipe(wiredep({
  35. directory: "./app/bower"
  36. /*, overrides: {
  37. "qtip2": {
  38. "main": ["./jquery.qtip.min.js", "./jquery.qtip.min.css"],
  39. "dependencies": {"jquery": ">=1.6.0"}
  40. }
  41. }*/
  42. //, exclude: ["bower/qtip2/"]
  43. //, ignorePath: /^(\.\.\/)*\.\./
  44. }))
  45. .pipe(gulp.dest("./app"));
  46. });
  47.  
  48. gulp.task("bower-json", function () {
  49. return gulp.watch("bower.json", ["wiredep-bower"]);
  50. });
  51.  
  52. // Следим за файлами
  53. gulp.task("watch", function () {
  54. gulp.watch([
  55. "./app/*.html",
  56. "./app/css/*.css",
  57. "./app/js/*.js"
  58. ]).on("change", browserSync.reload);
  59. });
  60.  
  61. // Дефолтный task
  62. gulp.task("default", ["server", "wiredep-bower", "bower-json", "watch"]);
  63.  
  64. var log = function (error) {
  65. console.log([
  66. "",
  67. "----------ERROR MESSAGE START----------",
  68. ("[" + error.name + " in " + error.plugin + "]"),
  69. error.message,
  70. "----------ERROR MESSAGE END----------",
  71. ""
  72. ].join("\n"));
  73. this.end();
  74. }
  75.  
  76.  
  77. /*******************************************
  78. * DIST
  79. ******************************************/
  80. // Переносим CSS JS HTML в папку DIST
  81. gulp.task("useref", function () {
  82. var assets = useref.assets();
  83. return gulp.src("./app/*.html")
  84. .pipe(assets)
  85. .pipe(gulpif("*.js", uglify()))
  86. .pipe(gulpif("*.css", minifyCss({compatibility: "ie8"})))
  87. .pipe(assets.restore())
  88. .pipe(useref())
  89. .pipe(gulp.dest("dist"));
  90. });
  91.  
  92. // Очищаем директорию DIST
  93. gulp.task("clean-dist", function () {
  94. return del(["./dist/**", "!./dist/"]);
  95. });
  96.  
  97. // Запускаем локальный сервер для DIST
  98. gulp.task("dist-server", function () {
  99. browserSync.init({
  100. notify: false,
  101. port: 2000,
  102. server: { baseDir: "./dist" }
  103. });
  104. });
  105.  
  106. // Перенос шрифтов
  107. gulp.task("fonts", function() {
  108. gulp.src("./app/fonts/*")
  109. .pipe(filter(["*.eot","*.svg","*.ttf","*.woff","*.woff2"]))
  110. .pipe(gulp.dest("./dist/fonts/"))
  111. });
  112.  
  113. // Перенос картинок
  114. gulp.task("images", function () {
  115. return gulp.src("./app/img/**/*")
  116. .pipe(imagemin({
  117. progressive: true,
  118. interlaced: true
  119. }))
  120. .pipe(gulp.dest("./dist/img"));
  121. });
  122.  
  123. // Перенос остальных файлов (favicon и т.д.)
  124. gulp.task("extras", function () {
  125. return gulp.src(["./app/*.*", "!./app/*.html"])
  126. .pipe(gulp.dest("./dist"));
  127. });
  128.  
  129. // Вывод размера папки APP
  130. gulp.task("size-app", function () {
  131. return gulp.src("app/**/*").pipe(size({title: "APP size: "}));
  132. });
  133.  
  134. // Сборка и вывод размера папки DIST
  135. gulp.task("dist", ["useref", "images", "fonts", "extras", "size-app"], function () {
  136. return gulp.src("dist/**/*").pipe(size({title: "DIST size: "}));
  137. });
  138.  
  139. // Собираем папку DIST - только когда файлы готовы
  140. gulp.task("build", ["clean-dist", "wiredep-bower"], function () {
  141. gulp.start("dist");
  142. });
  143.  
  144. // Отправка проекта на сервер
  145. gulp.task("deploy", function() {
  146. var conn = ftp.create({
  147. host: "host",
  148. user: "user",
  149. password: "password",
  150. parallel: 10,
  151. log: gutil.log
  152. });
  153.  
  154. return gulp.src(["./dist/**/*"], { base: "./dist/", buffer: false})
  155. .pipe(conn.dest("/public_html/"));
  156. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement