Use twig's {% spaceless %} tag only under certain conditions
You could do it by buffering your output, i.e.

{% set output %}
{# Your code here #}
{% endset %}

{% if isDev %}
     {{ output }}
{% else %}
    {% spaceless %}
        {{ output }}
    {% endspaceless %}
{% endif %}