Using topology optimization, we inverse-design nanophotonic cavities enabling the preparation of pure states of pairs and triples of quantum emitters. Our devices involve moderate values of the dielectric constant, operate under continuous laser driving, and yield fidelities to the target (Bell and W) states approaching unity for distant qubits (several natural wavelengths apart). In the fidelity optimization procedure, our algorithm generates entanglement by maximizing the dissipative coupling between the emitters, which allows the formation of multipartite pure steady states in the driven-dissipative dynamics of the system. Our findings open the way toward the efficient and fast preparation of multiqubit quantum states with engineered features, with potential applications for nonclassical light generation, and quantum sensing and metrology.