Timers and other features for Heroes of the Storm
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 

92 linhas
2.4 KiB

  1. 'use strict'
  2. require('./check-versions')()
  3. const config = require('../config')
  4. if (!process.env.NODE_ENV) {
  5. process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV)
  6. }
  7. const opn = require('opn')
  8. const path = require('path')
  9. const express = require('express')
  10. const webpack = require('webpack')
  11. const proxyMiddleware = require('http-proxy-middleware')
  12. const webpackConfig = require('./webpack.dev.conf')
  13. // default port where dev server listens for incoming traffic
  14. const port = process.env.PORT || config.dev.port
  15. // automatically open browser, if not set will be false
  16. const autoOpenBrowser = !!config.dev.autoOpenBrowser
  17. // Define HTTP proxies to your custom API backend
  18. // https://github.com/chimurai/http-proxy-middleware
  19. const proxyTable = config.dev.proxyTable
  20. const app = express()
  21. const compiler = webpack(webpackConfig)
  22. const devMiddleware = require('webpack-dev-middleware')(compiler, {
  23. publicPath: webpackConfig.output.publicPath,
  24. quiet: true
  25. })
  26. const hotMiddleware = require('webpack-hot-middleware')(compiler, {
  27. log: false
  28. })
  29. // force page reload when html-webpack-plugin template changes
  30. compiler.plugin('compilation', function (compilation) {
  31. compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) {
  32. hotMiddleware.publish({ action: 'reload' })
  33. cb()
  34. })
  35. })
  36. // enable hot-reload and state-preserving
  37. // compilation error display
  38. app.use(hotMiddleware)
  39. // proxy api requests
  40. Object.keys(proxyTable).forEach(function (context) {
  41. let options = proxyTable[context]
  42. if (typeof options === 'string') {
  43. options = { target: options }
  44. }
  45. app.use(proxyMiddleware(options.filter || context, options))
  46. })
  47. // handle fallback for HTML5 history API
  48. app.use(require('connect-history-api-fallback')())
  49. // serve webpack bundle output
  50. app.use(devMiddleware)
  51. // serve pure static assets
  52. const staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory)
  53. app.use(staticPath, express.static('./static'))
  54. const uri = 'http://localhost:' + port
  55. let _resolve
  56. const readyPromise = new Promise(resolve => {
  57. _resolve = resolve
  58. })
  59. console.log('> Starting dev server...')
  60. devMiddleware.waitUntilValid(() => {
  61. console.log('> Listening at ' + uri + '\n')
  62. // when env is testing, don't need open it
  63. if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
  64. opn(uri)
  65. }
  66. _resolve()
  67. })
  68. const server = app.listen(port)
  69. module.exports = {
  70. ready: readyPromise,
  71. close: () => {
  72. server.close()
  73. }
  74. }