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 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #Browsersync - Webpack + Preact Hot Loader
  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.preact-hot-loader
  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. To see `preact-hot-loader` in action, edit `js/HelloWorld.jsx`
  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 webpackHotMiddleware = require('webpack-hot-middleware');
  31. /**
  32. * Require ./webpack.config.js and make a bundler from it
  33. */
  34. var webpackConfig = require('./webpack.config.dev');
  35. var bundler = webpack(webpackConfig);
  36. /**
  37. *
  38. */
  39. browserSync.init({
  40. server: 'app',
  41. middleware: [
  42. webpackDevMiddleware(bundler, {
  43. // IMPORTANT: dev middleware can't access config, so we should
  44. // provide publicPath by ourselves
  45. publicPath: webpackConfig.output.publicPath,
  46. // pretty colored output
  47. stats: {colors: true}
  48. // for other settings see
  49. // http://webpack.github.io/docs/webpack-dev-middleware.html
  50. }),
  51. // bundler should be the same as above
  52. webpackHotMiddleware(bundler)
  53. ],
  54. // no need to watch '*.js' here, webpack will take care of it for us,
  55. // including full page reloads if HMR won't work
  56. files: [
  57. 'app/css/*.css',
  58. 'app/*.html'
  59. ]
  60. });
  61. ```