Webpack plugin that uses Babel to transpile output bundles for legacy browsers, including dependencies. Version 4.0.0 requires Node >=8. Unlike other solutions (e.g., babel-loader applied per file), it runs transpilation once per asset at the end of compilation, reducing build time. Key differentiator: it handles dependency transpilation automatically and supports custom browser targets via the Browserslist ecosystem.
npm install targets-webpack-pluginVerified import paths — ran on the pinned version, not inferred.
Configures the TargetsPlugin in a Next.js webpack config to transpile production bundles for legacy browsers.
Check that the plugin is only added when process.env.NODE_ENV === 'production' or similar.
Install webpack: npm install webpack --save-dev
Use object with 'browsers' key or rely on browserslist config file.
Run npm install --save-dev targets-webpack-plugin
Replace import with: const TargetsPlugin = require('targets-webpack-plugin');