Start Server NestJS Webpack Plugin

2.2.5 · abandoned · verified Sun Apr 19

This Webpack plugin (current stable version 2.2.5) automatically starts a Node.js server after Webpack's build process completes, primarily intended for development workflows. It streamlines the development loop by restarting the server on code changes, enabling features like Hot Module Reloading (HMR) for server-side code. The plugin allows configuration of the server's entry point via the `name` option, and supports passing arguments to both Node.js and the script itself for debugging or custom behaviors. While its name suggests a specific affinity for NestJS applications, its core functionality is broadly applicable to any Node.js server bundled with Webpack, acting as a convenient orchestrator for development environments. It helps eliminate manual server restarts during active development. However, it's critical to note that version 2.2.5 was last published approximately eight years ago, indicating the project is effectively abandoned and may not be compatible with recent versions of Webpack (v5+) or Node.js.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates configuring Webpack to use `start-server-nestjs-webpack-plugin` for a Node.js server with TypeScript, including setup for Hot Module Reloading and Node.js debugger integration. This setup is for a typical NestJS application server file located at './src/server.ts' and outputs to 'dist/server.js'.

import StartServerPlugin from "start-server-nestjs-webpack-plugin";
import nodeExternals from 'webpack-node-externals';
import webpack from 'webpack';

export default {
  // Target node for server-side bundling
  target: 'node',
  mode: 'development',
  entry: {
    server: ['webpack/hot/poll?100', './src/server.ts'], // Include HMR module
  },
  output: {
    filename: 'server.js',
    path: require('path').resolve(__dirname, 'dist'),
  },
  externals: [
    nodeExternals({ allowlist: ['webpack/hot/poll?100'] }), // Whitelist HMR module
  ],
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: 'ts-loader',
        exclude: /node_modules/,
      },
    ],
  },
  resolve: {
    extensions: ['.tsx', '.ts', '.js'],
  },
  plugins: [
    // Only use this in DEVELOPMENT
    new StartServerPlugin({
      name: 'server.js',
      nodeArgs: ['--inspect'], // allow debugging
      args: ['--env', 'development'], // pass args to script
      signal: 'SIGUSR2', // signal to send for HMR
      keyboard: true, // Allow typing 'rs' to restart the server.
    }),
    new webpack.HotModuleReplacementPlugin(), // Enable HMR
  ],
};

view raw JSON →