The first one is a find and replace nightmare on any sufficiently large project and akin to inline styling. The second negates the point of utility classes.
You'd often use something like a component based JS framework or a server rendered templating language, making it easy to contain all utilities with shared logic in one place.