I haven't tried it, and I would probably not try it with my own stepper motors. But maybe someone else here has and can advise you.
I would expect you to run into some practical difficulties (for example, you will probably not want to connect the motor end of the cable shield to the motor, so you will have to somehow cut it off and/or insulate it at or outside of the motor housing. Also, I'm not sure how much room would be available for making connections. And you would not want to disassemble and remove the rotor.).
Rather, I recall seeing a product (but I can't seem to find a link to it, maybe somebody else knows what I'm talking about) that was sort of an add-on enclosure that bolts to the rear of the stepper motor and allows you to make a neater-looking wiring connection.