Files
lucide/tools/rollup-plugins/plugins.js
T
Daud Tariq bfe90f03d9 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.
2026-11-12 08:20:16 +01:00

66 lines
1.7 KiB
JavaScript

import { visualizer } from 'rollup-plugin-visualizer';
import replace from '@rollup/plugin-replace';
import license from 'rollup-plugin-license';
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
? esbuild({
minify,
...esbuildOptions,
})
: null,
nodeResolve({
extensions: ['.js', '.ts', '.jsx', '.tsx'],
resolveOnly: [/^@lucide\/.*$/],
}),
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,
filename: `stats/${pkg.name}${minify ? '-min' : ''}.html`,
}),
].filter(Boolean);
export { license, visualizer, replace };
export default plugins;