You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

readme.md 2.3 KiB

3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #Browsersync - Gulp, SASS + Pug Templates
  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.pug
  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 is an upgraded version of [gulp.jade recipe](https://github.com/Browsersync/recipes/tree/master/recipes/gulp.jade) from [BrowserSync](https://github.com/browsersync/browser-sync) .
  22. Some useful links:
  23. - template engine : [pug documentation](https://pugjs.org/api/reference.html)
  24. (was: Jade)
  25. - and its integration with gulp: [gulp-pug](https://www.npmjs.com/package/gulp-pug)
  26. - css preprocessing : [node-sass](https://www.npmjs.com/package/node-sass)
  27. - and its integration with
  28. gulp: [gulp-sass](https://www.npmjs.com/package/gulp-pug)
  29. - and of course [gulp](https://github.com/gulpjs/gulp/blob/master/docs/README.md)
  30. ### Preview of `gulpfile.js`:
  31. ```js
  32. var gulp = require('gulp');
  33. var browserSync = require('browser-sync');
  34. var sass = require('gulp-sass');
  35. var pug = require('gulp-pug');
  36. var reload = browserSync.reload;
  37. /**
  38. * Compile pug files into HTML
  39. */
  40. gulp.task('templates', function() {
  41. var YOUR_LOCALS = {
  42. "message": "This app is powered by gulp.pug recipe for BrowserSync"
  43. };
  44. return gulp.src('./app/*.pug')
  45. .pipe(pug({
  46. locals: YOUR_LOCALS
  47. }))
  48. .pipe(gulp.dest('./dist/'));
  49. });
  50. /**
  51. * Important!!
  52. * Separate task for the reaction to `.pug` files
  53. */
  54. gulp.task('pug-watch', ['templates'], reload);
  55. /**
  56. * Sass task for live injecting into all browsers
  57. */
  58. gulp.task('sass', function () {
  59. return gulp.src('./app/scss/*.scss')
  60. .pipe(sass()).on('error', sass.logError)
  61. .pipe(gulp.dest('./dist/css'))
  62. .pipe(reload({stream: true}));
  63. });
  64. /**
  65. * Serve and watch the scss/pug files for changes
  66. */
  67. gulp.task('default', ['sass', 'templates'], function () {
  68. browserSync({server: './dist'});
  69. gulp.watch('./app/scss/*.scss', ['sass']);
  70. gulp.watch('./app/*.pug', ['pug-watch']);
  71. });
  72. ```