react-native-svg-asset-plugin
Version:
Asset plugin for importing SVG images in React Native
36 lines (29 loc) • 828 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.load = void 0;
const funcUtils = require('./utils/func');
/**
* Load sharp conditionally.
*
* Since the sharp library is quite larg, this is useful
* when you might not want to load the whole library
* at startup.
*/
const load = funcUtils.memo(async () => {
const sharp = require('sharp');
await warmup(sharp);
return sharp;
});
/**
* Warms up the sharp library, handling any warmup errors.
*/
exports.load = load;
async function warmup(sharp) {
// First run might cause a xmllib error, run safe warmup
// See https://github.com/lovell/sharp/issues/1593
try {
await sharp(Buffer.from(`<svg xmlns="http://www.w3.org/2000/svg"><rect width="1" height="1" /></svg>`, 'utf-8')).metadata();
} catch (_unused) {}
}