Its counter intuitive, but less/very careful washing of the motor when washing the bike, making sure to keep water away from bearings is I am sure the right approach.
I was lucky to have my first Yamaha motor replaced under warranty when it developed play in the bearing, right on the 2 year ownership point, and I think injudicious and too frequent washing of the bike may have played a part.
I have been very careful with the second motor, and so far so good, but I am by crank drive ebike standards a high mileage user, now approaching 13,000 miles on my 2015 bike, and the first motor lasted 6,000 miles before it was replaced.
I am still using my original 400Wh battery, and when I bought the bike I was more worried about the longevity of the battery than the motor.