start.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * React Static Boilerplate
  3. * https://github.com/koistya/react-static-boilerplate
  4. * Copyright (c) Konstantin Tarkus (@koistya) | MIT license
  5. */
  6. import browserSync from 'browser-sync';
  7. import webpack from 'webpack';
  8. import webpackDevMiddleware from 'webpack-dev-middleware';
  9. import webpackHotMiddleware from 'webpack-hot-middleware';
  10. global.watch = true;
  11. const config = require('./config')[0];
  12. const bundler = webpack(config);
  13. export default async () => {
  14. await require('./build')();
  15. browserSync({
  16. server: {
  17. baseDir: 'build',
  18. middleware: [
  19. webpackDevMiddleware(bundler, {
  20. // IMPORTANT: dev middleware can't access config, so we should
  21. // provide publicPath by ourselves
  22. publicPath: config.output.publicPath,
  23. // pretty colored output
  24. stats: config.stats,
  25. hot: true,
  26. historyApiFallback: true
  27. // for other settings see
  28. // http://webpack.github.io/docs/webpack-dev-middleware.html
  29. }),
  30. // bundler should be the same as above
  31. webpackHotMiddleware(bundler)
  32. ]
  33. },
  34. // no need to watch '*.js' here, webpack will take care of it for us,
  35. // including full page reloads if HMR won't work
  36. files: [
  37. 'build/**/*.css',
  38. 'build/**/*.html'
  39. ]
  40. });
  41. };