Skip to content

Instantly share code, notes, and snippets.

@giautm
Created March 15, 2022 12:43
Show Gist options
  • Save giautm/655596dc2bb63818598f61319173879a to your computer and use it in GitHub Desktop.
Save giautm/655596dc2bb63818598f61319173879a to your computer and use it in GitHub Desktop.
import { ConfigPlugin, withGradleProperties } from "@expo/config-plugins";
type PackagingOptionsProp = {
pickFirsts?: string[];
excludes?: string[];
merges?: string[];
doNotStrip?: string[];
};
export const withPackagingOptions: ConfigPlugin<PackagingOptionsProp> = (
config,
props
) => {
const toKey = (key: string) => `android.packagingOptions.${key}`;
const keys = Object.keys(props).map(toKey);
return withGradleProperties(config, (config) => {
config.modResults = config.modResults.filter((item) => {
if (item.type == "property" && keys.includes(item.key)) {
return false;
}
return true;
});
Object.entries(props).forEach(([key, value]) => {
if (value) {
config.modResults.push({
type: "property",
key: toKey(key),
value: value.join(","),
});
}
});
return config;
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment