app.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * Require Browsersync along with webpack and middleware for it
  3. */
  4. var browserSync = require('browser-sync').create();
  5. var webpack = require('webpack');
  6. var webpackDevMiddleware = require('webpack-dev-middleware');
  7. var stripAnsi = require('strip-ansi');
  8. /**
  9. * Require ./webpack.config.js and make a bundler from it
  10. */
  11. var webpackConfig = require('./webpack.config');
  12. var bundler = webpack(webpackConfig);
  13. /**
  14. * Reload all devices when bundle is complete
  15. * or send a fullscreen error message to the browser instead
  16. */
  17. bundler.plugin('done', function (stats) {
  18. if (stats.hasErrors() || stats.hasWarnings()) {
  19. return browserSync.sockets.emit('fullscreen:message', {
  20. title: "Webpack Error:",
  21. body: stripAnsi(stats.toString()),
  22. timeout: 100000
  23. });
  24. }
  25. browserSync.reload();
  26. });
  27. /**
  28. * Run Browsersync and use middleware for Hot Module Replacement
  29. */
  30. browserSync.init({
  31. server: 'app',
  32. open: false,
  33. logFileChanges: false,
  34. middleware: [
  35. webpackDevMiddleware(bundler, {
  36. publicPath: webpackConfig.output.publicPath,
  37. stats: {colors: true}
  38. })
  39. ],
  40. plugins: ['bs-fullscreen-message'],
  41. files: [
  42. 'app/css/*.css',
  43. 'app/*.html'
  44. ]
  45. });