PaulTondeur / grunt-cache-busting

Cache busting files and updating references
8 stars 13 forks source link

[RequireJS use case] template search regex is too greedy #13

Closed tastepwalle closed 9 years ago

tastepwalle commented 9 years ago

Great task^^

I had a minor scuffle with the template replace regex. I am using RequireJS standard script tag:

<script data-main="PATH/TO/MAIN/CACHEBUSTED/src.js" src="PATH/TO/requirejs.js"></script>

When I ran grunt-cache-busting with the following params:

replace: ['my/templates.html'],
replacement: 'src.js',
file: 'PATH/TO/MAIN/CACHEBUSTED/src.js',
cleanup: true

The regex ate my requirejs src attr and gave me:

<script data-main="PATH/TO/MAIN/CACHEBUSTED/src-HASH.js">

The fix is simple: put src before data-main. Maybe by design but, it should probably be noted somewhere if so.

I wish I could be more helpful and provide a fixed fork but I am swamped right now ㅜㅠ

ariesxje commented 9 years ago

I have a similar issue, which is worse.

While using RequireJS, we have

<script data-main="js/config" src="js/vendor/require.js"></script>

where the file name in the data-main tag doesn't have a extension. But the text replace regex is expecting an extension:

replacementWithoutExtension + "((\-?)(.+)*)" + replacementExtension

which eats everything following. So the result we have is

<script data-main="js/config-HASH

which is completely a syntax error. It doesn't solve the problem if I put the src tag before data-main, as it even eats up the closing quote and the closing tag. Please fix it.

PaulTondeur commented 9 years ago

I know something is going wrong here after a pull request was merged some time ago. This doesn't have my priority to fix right now, but feel free to propose a pull request that fixes this issue and I'll be happy to merge :-)

ariesxje commented 9 years ago

I think this issue is fixed since now the data-main attribute is correctly replaced. You can close it.

PaulTondeur commented 9 years ago

Resolved in pull request #14

tastepwalle commented 9 years ago

Awesome, thanks Paul!