Start Server Webpack Plugin

2.2.5 · abandoned · verified Sun Apr 19

start-server-webpack-plugin is a Webpack plugin designed to automatically launch a Node.js server process once Webpack's build completes, primarily for development environments. It allows developers to integrate server-side applications, such as Express, directly into their Webpack development workflow. The plugin supports features like Hot Module Replacement (HMR) for server-side code, debugging via Node.js arguments, and automatic server restarts on file changes. The current stable version is 2.2.5, however, the package has not been updated since March 2018, indicating it is no longer actively maintained. Newer Webpack versions (like Webpack 5) are not officially supported, leading users to seek alternatives or forks for compatibility. Key differentiators include its focused role in *starting* a server post-build, rather than providing a full development server like webpack-dev-server, and its ability to pass arguments directly to the Node.js process and the target script itself.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a typical Webpack configuration using `start-server-webpack-plugin` to compile and launch a Node.js server. It includes basic Hot Module Replacement (HMR) setup, debugging flags, and an example server structure.

const path = require('path');
const webpack = require('webpack');
const StartServerPlugin = require('start-server-webpack-plugin');

module.exports = {
  mode: 'development',
  target: 'node',
  entry: {
    server: [
      'webpack/hot/poll?1000',
      path.resolve(__dirname, 'src', 'server.js'),
    ],
  },
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: '[name].js',
  },
  watch: true,
  externals: [
    // In order to ignore all modules in node_modules folder from bundling
    /^[a-z\-0-9]+$/,
  ],
  plugins: [
    // Only use this in DEVELOPMENT
    new StartServerPlugin({
      name: 'server.js', // Must match the output filename for the server entry
      nodeArgs: ['--inspect'], // Allows attaching a Node.js debugger
      args: ['--dev-mode'], // Pass custom arguments to your server script
      signal: true, // Send SIGUSR2 to restart the server for HMR
      keyboard: true, // Allow 'rs' to restart from terminal
    }),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoEmitOnErrorsPlugin(), // Good practice for HMR
  ],
};

// src/server.js (example)
// const express = require('express');
// const app = express();
// const port = process.env.PORT || 3000;

// app.get('/', (req, res) => {
//   res.send('Hello from server! Updated: ' + new Date().toLocaleTimeString());
// });

// app.listen(port, () => {
//   console.log(`Server listening on port ${port}`);
// });

// if (module.hot) {
//   module.hot.accept();
//   module.hot.dispose(() => console.log('Server disposing...'));
// }

view raw JSON →