Elhebert / laravel-sri

Subresource Integrity hash generator for laravel
MIT License
40 stars 16 forks source link

Add option to enable/disable #86

Closed albertcito closed 1 year ago

albertcito commented 1 year ago

I'm working on my local with laravel-mix sometimes when I used npm run watch it return the follow error

Failed to find a valid digest in the 'integrity' attribute for resource 'http://localdomain.local/js/my_file.js' with computed SHA-384 integrity 'avsIfTUsuvuApNQVkz/IcsKC3iPmSSuZR3vbgtI+5Ezqyy1/RgGBVJMiz3gIgCbO'. The resource has been blocked.

But if I ran npm run prod (mix --production) it works. So I need to compile everything in order to make it work, I don't know how to solve it. I try to php artisan optimize or install everything again. But in any case it doesn't work.

So, could you add a option to add env variable to enable/disable the integrity validator?

Elhebert commented 1 year ago

Hello,

Could you provide code snippets to understand what you are doing?

ckovey commented 1 year ago

I believe @albertcito might be asking about the option to run it locally during watch. I ran into same issue and found myself here.

Your complimentary package says you can do .generateIntegrityHash({enabled: true}) in your mix file which seems to work.

Given that production is the default mode I now wonder if I should be handling things differently in the blade file which I'm currently just doing <link href="{{ mix('css/app.min.css') }}" rel="stylesheet" {{ Sri::html('css/app.min.css') }}>?

edit: Hmm, never mind. While it does work, watch no longer watches it seems. Removing {enabled: true} returns watch to its auto build behavior on file change.