Guest User

Untitled

a guest
Feb 19th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.48 KB | None | 0 0
  1. 'use strict';
  2.  
  3. const gulp = require("gulp");
  4. const gulpLoadPlugins = require("gulp-load-plugins");
  5. const del = require("del");
  6.  
  7. const bs = require("browser-sync").create();
  8. const wiredep = require("wiredep").stream;
  9.  
  10. const plugins = gulpLoadPlugins();
  11.  
  12. gulp.task('styles', () => {
  13. return gulp.src('src/styles/*.scss')
  14. .pipe(plugins.plumber())
  15. .pipe(plugins.sourcemaps.init())
  16. .pipe(plugins.sass.sync({
  17. outputStyle: 'expanded',
  18. precision: 10,
  19. // includePaths: ['']
  20. }).on('error', plugins.sass.logError))
  21. // .pipe(plugins.autoprefixer({
  22. // browsers: ['last 2 version']
  23. // }))
  24. .pipe(plugins.sourcemaps.write('.'))
  25. .pipe(gulp.dest('temp/styles'))
  26. .pipe(bs.stream({ match: "**/*.css" }));
  27. });
  28.  
  29. function lint(files, options) {
  30. return () => {
  31. return gulp.src(files)
  32. .pipe(bs.reload({
  33. stream: true,
  34. once: true
  35. }))
  36. .pipe(plugins.eslint(options))
  37. .pipe(plugins.eslint.format())
  38. .pipe(plugins.if(!bs.active, plugins.eslint.failAfterError()));
  39. };
  40. }
  41. const testLintOptions = {
  42. env: {
  43. mocha: true
  44. }
  45. };
  46.  
  47. gulp.task('lint', lint('src/scripts/**/*.js'));
  48.  
  49. gulp.task('lint:test', lint('test/spec/**/*.js', testLintOptions));
  50.  
  51. gulp.task('html', ['styles'], () => {
  52. return gulp.src('src/*.html')
  53. .pipe(plugins.useref({
  54. searchPath: ['temp', 'src', '.']
  55. }))
  56. .pipe(plugins.if('*.js', plugins.uglify()))
  57. .pipe(plugins.if('*.css', plugins.cssnano({
  58. compatibility: '*'
  59. })))
  60. .pipe(gulp.dest('dist'));
  61. });
  62.  
  63. gulp.task('reversion', ['html'], () => {
  64. return gulp.src('dist/*.html')
  65. .pipe(plugins.reversion())
  66. .pipe(plugins.if('*.html', plugins.htmlmin({
  67. collapseWhitespace: true,
  68. collapseBooleanAttributes: true,
  69. removeAttributeQuotes: true,
  70. removeComments: true,
  71. removeEmptyAttributes: true,
  72. removeScriptTypeAttributes: true,
  73. removeStyleLinkTypeAttributes: true,
  74. })))
  75. .pipe(gulp.dest('dist'));
  76. });
  77.  
  78. gulp.task('images', () => {
  79. return gulp.src('src/images/**/*')
  80. .pipe(plugins.if(plugins.if.isFile, plugins.cache(plugins.imagemin({
  81. progressive: true,
  82. interlaced: true,
  83. // don't remove IDs from SVGs, they are often used
  84. // as hooks for embedding and styling
  85. svgoPlugins: [{
  86. cleanupIDs: false
  87. }]
  88. }))
  89. .on('error', function(err) {
  90. console.log(err);
  91. this.end();
  92. })))
  93. .pipe(gulp.dest('dist/images'));
  94. });
  95.  
  96. gulp.task('fonts', () => {
  97. return gulp.src(require('main-bower-files')({
  98. filter: '**/*.{eot,svg,ttf,woff,woff2,otf}'
  99. }).concat('src/fonts/**/*'))
  100. .pipe(gulp.dest('temp/fonts'))
  101. .pipe(gulp.dest('dist/fonts'));
  102. });
  103.  
  104. gulp.task('extras', () => {
  105. return gulp.src([
  106. 'src/*',
  107. 'src/*.*',
  108. '!src/*.html'
  109. ], {
  110. dot: true
  111. }).pipe(gulp.dest('dist'));
  112. });
  113.  
  114. gulp.task('clean', del.bind(null, ['temp', 'dist', '.publish']));
  115.  
  116. gulp.task('serve', ['styles', 'fonts'], () => {
  117. bs.init({
  118. notify: false,
  119. port: 2015,
  120. server: {
  121. baseDir: ['temp', 'src'],
  122. routes: {
  123. '/bower_components': 'bower_components'
  124. }
  125. }
  126. });
  127.  
  128. gulp.watch([
  129. 'src/*.html',
  130. 'src/scripts/**/*.js',
  131. 'src/images/**/*',
  132. 'temp/fonts/**/*'
  133. ]).on('change', bs.reload);
  134.  
  135. gulp.watch('src/styles/**/*.scss', ['styles']);
  136. gulp.watch('src/fonts/**/*', ['fonts']);
  137. gulp.watch('bower.json', ['wiredep', 'fonts']);
  138. });
  139.  
  140. gulp.task('serve:dist', () => {
  141. bs.init({
  142. notify: false,
  143. port: 2015,
  144. server: {
  145. baseDir: ['dist']
  146. }
  147. });
  148. });
  149.  
  150. gulp.task('serve:test', () => {
  151. bs.init({
  152. notify: false,
  153. port: 2015,
  154. ui: false,
  155. server: {
  156. baseDir: 'test',
  157. routes: {
  158. '/bower_components': 'bower_components'
  159. }
  160. }
  161. });
  162.  
  163. gulp.watch('test/spec/**/*.js').on('change', bs.reload);
  164. gulp.watch('test/spec/**/*.js', ['lint:test']);
  165. });
  166.  
  167. // inject bower components
  168. gulp.task('wiredep', () => {
  169. gulp.src(['src/styles/*.scss', '!src/styles/_*.scss'])
  170. .pipe(wiredep({
  171. ignorePath: /^(\.\.\/)+/
  172. }))
  173. .pipe(gulp.dest('./src/styles'));
  174. gulp.src('./src/*.html')
  175. .pipe(wiredep({
  176. ignorePath: /^(\.\.\/)*\.\./
  177. }))
  178. .pipe(gulp.dest('./src'));
  179. });
  180.  
  181. gulp.task('build', ['lint', 'reversion', 'images', 'fonts', 'extras'], () => {
  182. return gulp.src('dist/**/*').pipe(plugins.size({
  183. title: 'build',
  184. gzip: true
  185. }));
  186. });
  187.  
  188. gulp.task('deploy', () => {
  189. return gulp.src('dist/**/*')
  190. .pipe(plugins.ghPages());
  191. });
  192.  
  193. gulp.task('default', ['clean'], () => {
  194. gulp.start('build');
  195. });
Add Comment
Please, Sign In to add comment