server.js 879 B

123456789101112131415161718192021222324252627282930
  1. // const opn = require('opn')
  2. const chalk = require('chalk')
  3. const express = require('express')
  4. const webpack = require('webpack')
  5. const history = require('connect-history-api-fallback')
  6. const webpackDevMiddleware = require('webpack-dev-middleware')
  7. const webpackHotMiddleware = require('webpack-hot-middleware')
  8. const config = require('../build/config')
  9. const webpackConfig = require('../build/webpack')('development', config)
  10. const app = express()
  11. const compiler = webpack(webpackConfig)
  12. app.use(history())
  13. app.use(webpackDevMiddleware(compiler, {
  14. logLevel: 'silent',
  15. publicPath: config.publicPath,
  16. }))
  17. app.use(webpackHotMiddleware(compiler, {
  18. log: false,
  19. path: '/__what',
  20. heartbeat: 2000,
  21. }))
  22. console.log(chalk.cyan('Starting the development server...\n'))
  23. app.listen(config.port, () => {
  24. // opn(`http://localhost:${config.port}`, { app: 'google chrome' })
  25. })