Fanfic has no doubt been around since, well, probably the very second story ever told. Somebody probably liked the first story so much that they used the same characters and had them kill an ocelot or giant weevel instead of a dinosaur.
Since that time, somebody has liked somebody else’s stories so much that they just had to write their own versions, even if those versions never found it into the official canon. Fast-forward to the late 20th Century, and fan fiction becomes just another profit stream for savvy media companies. And while Nicholas Meyer’s “The Seven-Percent Solution” is possibly the most artistically successful fanfic ever published — even if got up the noses of Holmes’ purists — it took the Star Trek people to really monetize fan fiction.