* @private * @returns {Promise }
()
| 1683 | * @returns {Promise<void>} |
| 1684 | */ |
| 1685 | async initialize() { |
| 1686 | this.setupHooks(); |
| 1687 | |
| 1688 | await this.setupApp(); |
| 1689 | await this.createServer(); |
| 1690 | |
| 1691 | if (this.options.webSocketServer) { |
| 1692 | const compilers = |
| 1693 | /** @type {MultiCompiler} */ |
| 1694 | (this.compiler).compilers || [this.compiler]; |
| 1695 | |
| 1696 | for (const compiler of compilers) { |
| 1697 | if (compiler.options.devServer === false) { |
| 1698 | continue; |
| 1699 | } |
| 1700 | |
| 1701 | await this.addAdditionalEntries(compiler); |
| 1702 | |
| 1703 | const webpack = |
| 1704 | compiler.webpack || |
| 1705 | /** @type {NonNullable<Awaited<ReturnType<typeof loadWebpackPeer>>>} */ ( |
| 1706 | await loadWebpackPeer() |
| 1707 | ); |
| 1708 | |
| 1709 | new webpack.ProvidePlugin({ |
| 1710 | __webpack_dev_server_client__: this.getClientTransport(), |
| 1711 | }).apply(compiler); |
| 1712 | |
| 1713 | // For universal targets `webpack/hot/emitter` uses Node's `events`, |
| 1714 | // which breaks in the browser. Swap it for webpack's `EventTarget` |
| 1715 | // emitter when available. |
| 1716 | if ( |
| 1717 | compiler.options.output.module && |
| 1718 | compiler.platform.web === null && |
| 1719 | compiler.platform.node === null |
| 1720 | ) { |
| 1721 | let emitter; |
| 1722 | |
| 1723 | try { |
| 1724 | emitter = cjsRequire.resolve("webpack/hot/emitter-event-target.js"); |
| 1725 | } catch { |
| 1726 | // older webpack versions do not ship the `EventTarget` emitter |
| 1727 | } |
| 1728 | |
| 1729 | if (emitter) { |
| 1730 | new webpack.NormalModuleReplacementPlugin( |
| 1731 | /emitter(\.js)?$/, |
| 1732 | (result) => { |
| 1733 | if ( |
| 1734 | /webpack[/\\]hot|webpack-dev-server[/\\]client/.test( |
| 1735 | result.context, |
| 1736 | ) |
| 1737 | ) { |
| 1738 | result.request = emitter; |
| 1739 | } |
| 1740 | }, |
| 1741 | ).apply(compiler); |
| 1742 | } |
no test coverage detected