From bfe90f03d97992041b4a8007e6e3581b8e948517 Mon Sep 17 00:00:00 2001 From: Daud Tariq <169019632+daud4653@users.noreply.github.com> Date: Thu, 12 Nov 2026 12:20:16 +0500 Subject: [PATCH] fix(lucide-react-native): include license banner once instead of in every module (#5194) With `preserveModules`, rollup-plugin-license prepends the @license banner to every emitted module, so all ~2,370 files in dist/esm and dist/cjs carried it. Minifiers keep @license comments, so consumer bundles ended up with the text repeated many times (#3744). Add an opt-in `licenseBannerExclude` option to the shared rollup plugins and use it in lucide-react-native to keep the banner only on `Icon`. Every icon imports `createLucideIcon`, which imports `Icon`, and direct use of the `Icon` component imports it too, so the license is still included in production builds, exactly once. Other packages are unchanged: the option defaults to no filtering. --- .../lucide-react-native/rollup.config.mjs | 9 +++++- tools/rollup-plugins/plugins.js | 30 +++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/packages/lucide-react-native/rollup.config.mjs b/packages/lucide-react-native/rollup.config.mjs index 2d81d1c14..6e53af8ca 100644 --- a/packages/lucide-react-native/rollup.config.mjs +++ b/packages/lucide-react-native/rollup.config.mjs @@ -37,9 +37,16 @@ const bundles = [ const typesModuleMatcher = /[/\\]src[/\\]types\.(d\.)?ts$/; +// With `preserveModules`, every output module would get its own license banner, which +// repeats it ~2,000 times in consumer bundles (#3744). Every icon, and any direct use of +// the `Icon` component, imports `Icon`, so keeping the banner only there includes it +// exactly once in any bundle that renders an icon. +const licenseModuleMatcher = /[/\\]src[/\\]Icon\.ts$/; +const isNotLicenseChunk = (chunk) => !licenseModuleMatcher.test(chunk.facadeModuleId ?? ''); + const configs = bundles.map(({ inputs, outputDir, format, preserveModules, extension = 'js' }) => ({ input: inputs, - plugins: plugins({ pkg }), + plugins: plugins({ pkg, licenseBannerExclude: isNotLicenseChunk }), external: ['react', 'react-native-svg'], output: { name: packageName, diff --git a/tools/rollup-plugins/plugins.js b/tools/rollup-plugins/plugins.js index d150355a7..34da25dec 100644 --- a/tools/rollup-plugins/plugins.js +++ b/tools/rollup-plugins/plugins.js @@ -5,12 +5,33 @@ import esbuild from 'rollup-plugin-esbuild'; import { nodeResolve } from '@rollup/plugin-node-resolve'; import summary from 'rollup-plugin-summary'; +/** + * Wraps a plugin's `renderChunk` hook so it is skipped for chunks matching `exclude`. + * Used to keep the license banner to a single chunk that every consumer path imports, + * instead of repeating it in every module emitted with `preserveModules`. + */ +const skipRenderChunk = (plugin, exclude) => { + if (!exclude) return plugin; + + const { renderChunk } = plugin; + + return { + ...plugin, + renderChunk(code, chunk, ...rest) { + if (exclude(chunk)) return null; + + return renderChunk.call(this, code, chunk, ...rest); + }, + }; +}; + const plugins = ({ pkg, minify = false, withEsbuild = true, esbuildOptions = {}, withSummary = false, + licenseBannerExclude, }) => [ withEsbuild @@ -23,12 +44,15 @@ const plugins = ({ extensions: ['.js', '.ts', '.jsx', '.tsx'], resolveOnly: [/^@lucide\/.*$/], }), - license({ - banner: `@license ${pkg.name} v${pkg.version} - ${pkg.license} + skipRenderChunk( + license({ + banner: `@license ${pkg.name} v${pkg.version} - ${pkg.license} This source code is licensed under the ${pkg.license} license. See the LICENSE file in the root directory of this source tree.`, - }), + }), + licenseBannerExclude, + ), withSummary ? summary() : null, visualizer({ sourcemap: true,