I finally figured it out. In case someone else runs into the same problem I'll post the solution. The server side asset compilation doesn't support double quotes in the .media-width()
mixin arguments.
I.e.:
.media-width(@extremum, @break) when (@extremum = "max") and (@break = @screen__m) {
will work fine when compiled with Grunt but not at all when using the server side asset compilation.
To make it work on both you need to use:
.media-width(@extremum, @break) when (@extremum = 'max') and (@break = @screen__m) {