Write letters to her for her mom to give her at various points in her life. Birthdays, christmases, High school graduation, College graduation, wedding, births of children.
Tell your exwife. Then you can tell your daughter together.
A unified front is important here, I think, if for no other reason than your ex will be dealing with this as much as you in your remaining time.
At some point, you’ll want to sit her down and prepare her for what your remaining time will look like. Talk about how you’ll get sick and what that will look like. She’s old enough to understand what you being sick might look like.