Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

readme.md 1.9 KiB

3 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #Browsersync - Gulp & Ruby SASS
  2. ## Installation/Usage:
  3. To try this example, follow these 4 simple steps.
  4. **Step 1**: Clone this entire repo
  5. ```bash
  6. $ git clone https://github.com/Browsersync/recipes.git bs-recipes
  7. ```
  8. **Step 2**: Move into the directory containing this example
  9. ```bash
  10. $ cd bs-recipes/recipes/gulp.ruby.sass
  11. ```
  12. **Step 3**: Install dependencies
  13. ```bash
  14. $ npm install
  15. ```
  16. **Step 4**: Run the example
  17. ```bash
  18. $ npm start
  19. ```
  20. ### Additional Info:
  21. This example highlights both the stream support for injecting CSS, aswell
  22. as the support for calling `reload` directly following html changes.
  23. We also need to filter out any source maps created by ruby-sass.
  24. ### Preview of `gulpfile.js`:
  25. ```js
  26. var gulp = require('gulp');
  27. var browserSync = require('browser-sync');
  28. var filter = require('gulp-filter');
  29. var sass = require('gulp-ruby-sass');
  30. var sourcemaps = require('gulp-sourcemaps');
  31. var reload = browserSync.reload;
  32. var src = {
  33. scss: 'app/scss/*.scss',
  34. css: 'app/css',
  35. html: 'app/*.html'
  36. };
  37. /**
  38. * Kick off the sass stream with source maps + error handling
  39. */
  40. function sassStream () {
  41. return sass('app/scss', {sourcemap: true})
  42. .on('error', function (err) {
  43. console.error('Error!', err.message);
  44. })
  45. .pipe(sourcemaps.write('./', {
  46. includeContent: false,
  47. sourceRoot: '/app/scss'
  48. }));
  49. }
  50. /**
  51. * Start the Browsersync Static Server + Watch files
  52. */
  53. gulp.task('serve', ['sass'], function() {
  54. browserSync({
  55. server: "./app"
  56. });
  57. gulp.watch(src.scss, ['sass']);
  58. gulp.watch(src.html).on('change', reload);
  59. });
  60. /**
  61. * Compile sass, filter the results, inject CSS into all browsers
  62. */
  63. gulp.task('sass', function() {
  64. return sassStream()
  65. .pipe(gulp.dest(src.css))
  66. .pipe(filter("**/*.css"))
  67. .pipe(reload({stream: true}));
  68. });
  69. /**
  70. * Default task
  71. */
  72. gulp.task('default', ['serve']);
  73. ```