Skip to content

Commit

Permalink
fix(react-native): support React Native buildable libs that do not us…
Browse files Browse the repository at this point in the history
…e SVGR (#13909)
  • Loading branch information
jaysoo committed Dec 19, 2022
1 parent 915dc25 commit 9ac6366
Showing 1 changed file with 20 additions and 14 deletions.
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

0 comments on commit 9ac6366

Please sign in to comment.