forked from kristerkari/react-native-svg-transformer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (36 loc) · 1.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const { resolveConfig, transform } = require("@svgr/core");
const resolveConfigDir = require("path-dirname");
const upstreamTransformer = require("metro-react-native-babel-transformer");
const defaultSVGRConfig = {
native: true,
plugins: ["@svgr/plugin-svgo", "@svgr/plugin-jsx"],
svgoConfig: {
plugins: [{
name: "preset-default",
params: {
overrides: {
inlineStyles: {
onlyMatchedOnce: false
},
removeViewBox: false,
removeUnknownsAndDefaults: false,
convertColors: false
}
}
}]
}
};
module.exports.transform = async({ src, filename, options }) => {
if (filename.endsWith(".svg")) {
const config = await resolveConfig(resolveConfigDir(filename));
const svgrConfig = config
? { ...defaultSVGRConfig, ...config }
: defaultSVGRConfig;
return upstreamTransformer.transform({
src: await transform(src, svgrConfig),
filename,
options
});
}
return upstreamTransformer.transform({ src, filename, options });
};