They definitely had lunar/space themed sets in the '80s, but they were generic (at least the ones I had). I don't recall when the Star Wars sets came out, they might have been one of the first cross-promotional tie-ins that Lego did?
Prior to Star Wars, they had Shell, Exxon, and Esso branded sets. I think sometimes they licensed the Ferrari brand as well.
And yes, Lego has had a Space theme since the late 70s. But it was a general "Space" theme. They would later make Space Police, Blacktron, Magnetron, etc.
But actual Star Wars was 1998. I have some of those sets. It was a big deal to get an actual lightsaber hilt and blade.