A strategy of on-device phase engineering of two-dimensional materials is proposed, allowing the in situ realization of various lattice phases with distinct stoichiometries and versatile functions.