Skip to content

Instantly share code, notes, and snippets.

@ozcanzaferayan
Created February 25, 2024 09:55
Show Gist options
  • Save ozcanzaferayan/2ac9cae80f07bda2e3e21be1fef42d4d to your computer and use it in GitHub Desktop.
Save ozcanzaferayan/2ac9cae80f07bda2e3e21be1fef42d4d to your computer and use it in GitHub Desktop.
Expo create custom plugin
import type { ConfigContext, ExpoConfig } from "@expo/config";
const defineConfig = (_: ConfigContext): ExpoConfig => ({
name: "My project",
slug: "my-project",
plugins: [
["./plugins/mylibrary.plugin.js"],
],
});
export default defineConfig;
const {
withAppBuildGradle,
withProjectBuildGradle,
} = require("expo/config-plugins");
module.exports = (config) => {
config = withProjectBuildGradle(config, (config) => {
const projectGradle = config.modResults;
// Add kotlin plugins
projectGradle.contents = projectGradle.contents.replace(
"dependencies {",
'dependencies {\n\t\tclasspath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"'
);
return config;
});
config = withAppBuildGradle(config, (config) => {
const appGradle = config.modResults;
// Add kotlin plugins
appGradle.contents = appGradle.contents.replace(
'apply plugin: "com.android.application"',
'apply plugin: "com.android.application"\napply plugin: "kotlin-android"\napply plugin: "kotlin-kapt"'
);
// Add databinding
appGradle.contents = appGradle.contents.replace(
"android {",
"android {\n\tbuildFeatures {\n\t\tdataBinding true\n\t}"
);
return config;
});
return config;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment