start.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 hygienistMiddleware from 'hygienist-middleware';
  9. import webpackDevMiddleware from 'webpack-dev-middleware';
  10. import webpackHotMiddleware from 'webpack-hot-middleware';
  11. global.watch = true;
  12. const config = require('./config')[0];
  13. const bundler = webpack(config);
  14. export default async () => {
  15. await require('./build')();
  16. browserSync({
  17. server: {
  18. baseDir: 'build',
  19. middleware: [
  20. hygienistMiddleware('build'),
  21. webpackDevMiddleware(bundler, {
  22. // IMPORTANT: dev middleware can't access config, so we should
  23. // provide publicPath by ourselves
  24. publicPath: config.output.publicPath,
  25. // pretty colored output
  26. stats: config.stats,
  27. hot: true,
  28. historyApiFallback: true,
  29. // for other settings see
  30. // http://webpack.github.io/docs/webpack-dev-middleware.html
  31. }),
  32. // bundler should be the same as above
  33. webpackHotMiddleware(bundler),
  34. ],
  35. },
  36. // no need to watch '*.js' here, webpack will take care of it for us,
  37. // including full page reloads if HMR won't work
  38. files: [
  39. 'build/**/*.css',
  40. 'build/**/*.html',
  41. ],
  42. });
  43. };