dciccale / grunt-processhtml

Process html files at build time to modify them depending on the release environment
MIT License
407 stars 30 forks source link

Retain attributes in script tags #112

Closed walmik closed 6 years ago

walmik commented 6 years ago

Hi there, I ve been using this Grunt plugin for over 3 years now and it works great! This is how my code looks:

<!-- build:js inline -->
    <!-- build:[src] js/ -->
        <script src="{jsBaseUrl}/main.js"></script>
    <!-- /build -->
<!-- /build -->

Recently i ve needed to add a nonce attribute to the script tag. Unfortunately the following doesnt work as expected:

<!-- build:js inline -->
    <!-- build:[src] js/ -->
        <script nonce="{nonce}" src="{jsBaseUrl}/main.js"></script>
    <!-- /build -->
<!-- /build -->

The nonce attribute is not retained and the processed HTML only has a script tag with the main.js content inside it. Is there some way I can retain the nonce attribute in the processed html?

walmik commented 6 years ago

Closing this issue as the following worked for me:

<!-- build:[nonce] {nonce} -->
    <!-- build:js inline js/signin-split.js -->
        <script nonce="{nonce}" src="{context.links.jsBaseUrl|ha|s}/signin-split.js"></script>
    <!-- /build -->
<!-- /build -->

And this one works with an additional task in the Gruntfile,

<!-- build:[nonce] {nonce} -->
    <!-- build:js inline -->
        <!-- build:[src] js/ -->
            <script nonce="{nonce}" src="{context.links.jsBaseUrl|ha|s}/signin-split.js"></script>
        <!-- /build -->
    <!-- /build -->
<!-- /build -->