Webpack Delete Sourcemaps Plugin

1.3.1 · active · verified Sun Apr 19

The `webpack-delete-sourcemaps-plugin` is a Webpack plugin designed to automatically remove sourcemap files at the conclusion of a build process. This is particularly useful for workflows involving services like Sentry, where sourcemaps are uploaded for error tracking but should not be exposed on production servers due to security risks (source code disclosure). The current stable version is `1.3.1`, with recent updates indicating active maintenance, including improvements for Webpack 4 compatibility since `v1.3.0`. A key differentiator is its explicit handling of the `devtool: 'hidden-source-map'` configuration to prevent browsers from requesting non-existent sourcemaps, and providing tailored guidance for integration with Next.js and Sentry.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic Webpack integration and advanced usage within a Next.js configuration, emphasizing `hidden-source-map` and server-side sourcemap retention.

import { DeleteSourceMapsPlugin } from 'webpack-delete-sourcemaps-plugin';
import type { Configuration } from 'webpack';

interface NextWebpackConfigOptions {
  isServer: boolean;
  dev: boolean;
  // ... other Next.js specific options
}

// Basic Webpack Configuration Example
const webpackConfig: Configuration = {
  mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
  devtool: 'hidden-source-map', // Recommended to prevent 404s for deleted sourcemaps
  entry: './src/index.js',
  output: {
    filename: '[name].js',
    path: __dirname + '/dist',
    clean: true
  },
  plugins: [
    new DeleteSourceMapsPlugin({
      // Optional: keepServerSourcemaps: true
      // Optional: silent: true
    })
  ]
};

// Example with Next.js (in next.config.js)
const nextConfigWebpack = (config: Configuration, options: NextWebpackConfigOptions) => {
  // For Next.js, 'hidden-source-map' is often managed by sentry-webpack-plugin
  // This plugin can override it for client builds if necessary.
  config.plugins?.push(
    new DeleteSourceMapsPlugin({
      isServer: options.isServer,
      keepServerSourcemaps: true, // Typically keep sourcemaps for server builds in Next.js
      silent: process.env.CI === 'true' // Reduce console output in CI/CD
    })
  );
  return config;
};

// In a real setup, you'd export these configs appropriately.
// For demonstration purposes:
console.log('Webpack configuration for deletion plugin:', webpackConfig);
// console.log('Next.js webpack config callback:', nextConfigWebpack);

view raw JSON →