Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

3 lat temu
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #Browsersync - Server includes example
  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/server.includes
  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. ### Preview of `app.js`:
  22. ```js
  23. /**
  24. * Require Browsersync
  25. */
  26. var browserSync = require('browser-sync').create();
  27. var fs = require('fs');
  28. /**
  29. * Run Browsersync with server config
  30. */
  31. browserSync.init({
  32. server: 'app',
  33. files: ['app/*.html', 'app/css/*.css'],
  34. rewriteRules: [
  35. {
  36. match: /@include\("(.+?)"\)/g,
  37. fn: function (match, filename) {
  38. if (fs.existsSync(filename)) {
  39. return fs.readFileSync(filename);
  40. } else {
  41. return '<span style="color: red">'+filename+' could not be found</span>';
  42. }
  43. }
  44. }
  45. ]
  46. });
  47. ```