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.
npm install webpack-delete-sourcemaps-pluginVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic Webpack integration and advanced usage within a Next.js configuration, emphasizing `hidden-source-map` and server-side sourcemap retention.
Ensure `webpack-delete-sourcemaps-plugin` is correctly configured in your production Webpack build to delete sourcemaps after any upload steps (e.g., to Sentry).
Set `devtool: 'hidden-source-map'` in your Webpack configuration. For Next.js, the plugin can handle overriding `devtool` for client builds, even when `sentry-webpack-plugin` is used.
Upgrade to `webpack-delete-sourcemaps-plugin@1.3.0` or newer if you require Webpack 4 support. Ensure your Webpack setup matches the plugin's stated compatibility.
Pass the `isServer` flag from your `next.config.js` webpack callback to the plugin, and consider `keepServerSourcemaps: true` if you need them for server-side debugging or error reporting.
Run `npm install webpack-delete-sourcemaps-plugin --save-dev` or `yarn add webpack-delete-sourcemaps-plugin --dev`.
Ensure `devtool: 'hidden-source-map'` is set in your Webpack configuration. The plugin helps manage this, especially for Next.js builds.
Use a named import: `import { DeleteSourceMapsPlugin } from 'webpack-delete-sourcemaps-plugin';` or `const { DeleteSourceMapsPlugin } = require('webpack-delete-sourcemaps-plugin');`