vuejs-templates / webpack

A full-featured Webpack + vue-loader setup with hot reload, linting, testing & css extraction.
MIT License
9.71k stars 4.4k forks source link

HMR with express server with NodeJS API #1511

Open Schachte opened 4 years ago

Schachte commented 4 years ago

My goal here is to get a bundle for my serverside express bundle with HMR support using the webpack NodeJS API. I'm not quite sure if I'm approaching this problem correctly.

  // returns 2 item array [0] = client [1] = server
  const config = webpackConfig();

  const devServer = { host, port, ...config.devServer }

  WebpackDevServer.addDevServerEntrypoints(config[0], devServer)

  const compiler = webpack(config)
  const server = new WebpackDevServer(compiler, devServer)

  server.listen(port, host, err => {
    if (err) {
      console.error(err)
      process.exit(1)
    } else if (args.open) {
      openBrowser(`http://${host}:${port}${publicPath}/`)
    }
  })

I'm hoping that the server for node (express) will be running as well as the clientside bundle. How can I achieve this?