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.

пре 3 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #Browsersync - Webpack + Babel
  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/webpack.babel
  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. Edit any files within the `src` folder
  22. ### Preview of `app.js`:
  23. ```js
  24. /**
  25. * Require Browsersync along with webpack and middleware for it
  26. */
  27. var browserSync = require('browser-sync').create();
  28. var webpack = require('webpack');
  29. var webpackDevMiddleware = require('webpack-dev-middleware');
  30. var stripAnsi = require('strip-ansi');
  31. /**
  32. * Require ./webpack.config.js and make a bundler from it
  33. */
  34. var webpackConfig = require('./webpack.config');
  35. var bundler = webpack(webpackConfig);
  36. /**
  37. * Reload all devices when bundle is complete
  38. * or send a fullscreen error message to the browser instead
  39. */
  40. bundler.plugin('done', function (stats) {
  41. if (stats.hasErrors() || stats.hasWarnings()) {
  42. return browserSync.sockets.emit('fullscreen:message', {
  43. title: "Webpack Error:",
  44. body: stripAnsi(stats.toString()),
  45. timeout: 100000
  46. });
  47. }
  48. browserSync.reload();
  49. });
  50. /**
  51. * Run Browsersync and use middleware for Hot Module Replacement
  52. */
  53. browserSync.init({
  54. server: 'app',
  55. open: false,
  56. logFileChanges: false,
  57. middleware: [
  58. webpackDevMiddleware(bundler, {
  59. publicPath: webpackConfig.output.publicPath,
  60. stats: {colors: true}
  61. })
  62. ],
  63. plugins: ['bs-fullscreen-message'],
  64. files: [
  65. 'app/css/*.css',
  66. 'app/*.html'
  67. ]
  68. });
  69. ```