You could use Platform dependent compilation blocks in your scripts, so certain parts would be compiled just if they are in a specific platform. Example:
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class PrefabCreatorExample : MonoBehaviour
{
public string path;
private void Start()
{
#if UNITY_EDITOR
PrefabUtility.CreatePrefab(path, GenerateObject());
#endif
}
private GameObject GenerateObject()
{
GameObject newObject = new GameObject();
// Your creation logic here...
return newObject;
}
}
I use this a lot to write Gizmos' attributes for the Editor without generating unnecessary data types on the final build.
You could also use Inspector classes that will only be compiled on Editor mode, this scrips must be on Editor's folder of course. With this solution you separate the Game's functionality from the Editor's (on this case, I have created the PrefabUtilities MonoBehaviour class). Example:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(PrefabUtilities))]
public class PrefabUtilitiesInspector : Editor
{
private PrefabUtilities prefabUtilities; /// <summary>Inspector's Target.</summary>
/// <summary>Sets target property.</summary>
void OnEnable()
{
prefabUtilities = target as PrefabUtilities;
}
/// <summary>OnInspectorGUI override.</summary>
public override void OnInspectorGUI()
{
DrawDefaultInspector();
if(GUILayout.Button("Substitute with Prefab.")) prefabUtilities.SubstituteGameObjectsForPrefab();
}
}
This would draw a button on the inspector, but you can also do the Editor's exclusive logic there.

Hope it helps.