I remember making something like that when I was a kid riding an AMF Hercules 3-speed.
Used a micro limit switch with a long actuater lever on it under the front brake lever, so squeezing the lever would close the switch without interfering with the operation of the lever. A pair of D cells were slung under the saddle in a plastic battery holder salvaged from some broken toy, and IIRC, the tailight actually had STOP across it, like the old schoolbus lights had. Strictly on/off affair; no runlight.
A fun project, not sure how useful it was really.