Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(react-native): support React Native buildable libs that do not use SVGR #13909

Merged
merged 1 commit into from Dec 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 20 additions & 14 deletions packages/react/plugins/bundle-rollup.ts
@@ -1,8 +1,5 @@
import * as rollup from 'rollup';

const url = require('@rollup/plugin-url');
const svg = require('@svgr/rollup');

function getRollupOptions(options: rollup.RollupOptions) {
const extraGlobals = {
react: 'React',
Expand All @@ -26,17 +23,26 @@ function getRollupOptions(options: rollup.RollupOptions) {
};
}

options.plugins = [
svg({
svgo: false,
titleProp: true,
ref: true,
}),
url({
limit: 10000, // 10kB
}),
...options.plugins,
];
// React buildable libs support SVGR, but not for React Native.
// If imports fail, ignore it.
try {
const url = require('@rollup/plugin-url');
const svg = require('@svgr/rollup');

options.plugins = [
svg({
svgo: false,
titleProp: true,
ref: true,
}),
url({
limit: 10000, // 10kB
}),
...options.plugins,
];
} catch {
// Ignored for React Native
}

return options;
}
Expand Down