start.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 webpackConfig = require('./webpack.config')[0];
  13. const bundler = webpack(webpackConfig);
  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: webpackConfig.output.publicPath,
  25. // pretty colored output
  26. stats: webpackConfig.stats,
  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. };