If you can become part of a collective story, a story that will continue beyond your death, and if you believe in that story and can find a role in it that gets you out of bed in the morning, then death will not undercut the meaning of your life.
That story doesn’t have to be the stuff of history. Anything you care deeply about will do: your family, your community, the progress of science, the healing of our social or physical environment — anything. And you don’t have to be the Nobel-Prize-winning star of the story. All you have to do is contribute. Affect the plot in some positive way, and you can go on telling meaningful stories about your life right up to the moment you die.