lbundle
Version:
Small zero-configuration bundler build on top of Rollup.js and SWC for NPM libraries
57 lines (54 loc) • 1.75 kB
JavaScript
import url from '@rollup/plugin-url';
import svgr from '@svgr/rollup';
import { assetExtensions, svgExtensions } from '../constants/asset-extensions.mjs';
const getRollupAssetPlugins = ()=>{
return [
// Custom plugin to handle ?url suffix
{
name: 'url-suffix-handler',
resolveId (id) {
if (id.endsWith('?url')) {
// Remove the ?url suffix and resolve the actual file
const actualId = id.slice(0, -4);
return actualId;
}
return null;
}
},
// Handle SVG files with dual support: React components and URL imports
svgr({
exportType: 'named',
ref: true,
svgo: true,
titleProp: true,
include: '**/*.svg'
}),
// Handle all asset files including SVGs
url({
include: [
...assetExtensions,
...svgExtensions
].map((ext)=>`**/*${ext}`),
limit: 8192,
fileName: 'public/[name]-[hash][extname]',
publicPath: './'
})
];
};
const getRollupAssetPluginsForBin = ()=>{
// For binary builds, we typically don't want to inline assets
// and we don't need React component support for SVGs
return [
url({
include: [
...assetExtensions,
...svgExtensions
].map((ext)=>`**/*${ext}`),
limit: 0,
fileName: 'assets/[name]-[hash][extname]',
publicPath: './'
})
];
};
export { getRollupAssetPlugins, getRollupAssetPluginsForBin };
//# sourceMappingURL=get-rollup-asset-plugins.mjs.map