webserver.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Do this as the first thing so that any code reading it knows the right env.
  2. process.env.BABEL_ENV = 'development';
  3. process.env.NODE_ENV = 'development';
  4. process.env.ASSET_PATH = '/';
  5. const WebpackDevServer = require('webpack-dev-server');
  6. const webpack = require('webpack');
  7. const path = require('path');
  8. const config = require('../webpack.config');
  9. const env = require('./env');
  10. const options = config.chromeExtensionBoilerplate || {};
  11. const excludeEntriesToHotReload = options.notHotReload || [];
  12. /* eslint-disable-next-line */
  13. for (const entryName in config.entry) {
  14. if (excludeEntriesToHotReload.indexOf(entryName) === -1) {
  15. config.entry[entryName] = [
  16. `webpack-dev-server/client?http://localhost:${env.PORT}`,
  17. 'webpack/hot/dev-server',
  18. ].concat(config.entry[entryName]);
  19. }
  20. }
  21. config.plugins = [new webpack.HotModuleReplacementPlugin()].concat(
  22. config.plugins || []
  23. );
  24. delete config.chromeExtensionBoilerplate;
  25. const compiler = webpack(config);
  26. const server = new WebpackDevServer(compiler, {
  27. https: false,
  28. hot: true,
  29. injectClient: false,
  30. writeToDisk: true,
  31. port: env.PORT,
  32. contentBase: path.join(__dirname, '../build'),
  33. publicPath: `http://localhost:${env.PORT}`,
  34. headers: {
  35. 'Access-Control-Allow-Origin': '*',
  36. },
  37. disableHostCheck: true,
  38. });
  39. if (process.env.NODE_ENV === 'development' && module.hot) {
  40. module.hot.accept();
  41. }
  42. server.listen(env.PORT);