Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

vor 3 Jahren
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #Browsersync - Browserify, Babelify + Watchify + Sourcemaps 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/gulp.browserify
  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 one is a beast. Write your React JSX code, in ES6, compiled by Browserify and auto-reload all devices
  22. when the compilation is complete.
  23. ### Preview of `gulpfile.js`:
  24. ```js
  25. var gulp = require('gulp');
  26. var gutil = require('gulp-util');
  27. var source = require('vinyl-source-stream');
  28. var babelify = require('babelify');
  29. var watchify = require('watchify');
  30. var exorcist = require('exorcist');
  31. var browserify = require('browserify');
  32. var browserSync = require('browser-sync').create();
  33. // Watchify args contains necessary cache options to achieve fast incremental bundles.
  34. // See watchify readme for details. Adding debug true for source-map generation.
  35. watchify.args.debug = true;
  36. // Input file.
  37. var bundler = watchify(browserify('./app/js/app.js', watchify.args));
  38. // Babel transform
  39. bundler.transform(babelify.configure({
  40. sourceMapRelative: 'app/js'
  41. }));
  42. // On updates recompile
  43. bundler.on('update', bundle);
  44. function bundle() {
  45. gutil.log('Compiling JS...');
  46. return bundler.bundle()
  47. .on('error', function (err) {
  48. gutil.log(err.message);
  49. browserSync.notify("Browserify Error!");
  50. this.emit("end");
  51. })
  52. .pipe(exorcist('app/js/dist/bundle.js.map'))
  53. .pipe(source('bundle.js'))
  54. .pipe(gulp.dest('./app/js/dist'))
  55. .pipe(browserSync.stream({once: true}));
  56. }
  57. /**
  58. * Gulp task alias
  59. */
  60. gulp.task('bundle', function () {
  61. return bundle();
  62. });
  63. /**
  64. * First bundle, then serve from the ./app directory
  65. */
  66. gulp.task('default', ['bundle'], function () {
  67. browserSync.init({
  68. server: "./app"
  69. });
  70. });
  71. ```