Luismahou / grunt-hashres

Hashes your js and css files and rename the <script> and <link> declarations that refer to them in your html/php/etc files.
MIT License
115 stars 41 forks source link

Feature: Custom format for find and replace text #11

Closed bregenspan closed 11 years ago

bregenspan commented 11 years ago

For a project I'm working on, I wanted to replace in require.js-formatted script tags, for example transforming:

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

to:

<script data-main="js/main.7dcb450a" src="js/lib/require.js"></script>

This isn't possible out-of-the-box because matching is done by full file basename, including extension. So I added optional ability to set the find and replace match formats to something distinct from the filename format in: https://github.com/bregenspan/grunt-hashres/commit/af8bf7986365860a91d94ffea0847733d2562329

Setting two extra format strings strikes me as a bit inelegant but I have yet to come up with a nicer approach for it.

@luismahou - is this the kind of feature you'd consider for core? If so I'll clean things up and add tests + do a pull request.

Thanks for the very useful module! -Ben

bregenspan commented 11 years ago

Due to the above style (filename different from module name, but not set in paths config) not really being the recommended Require.js way, and apparently failing for some (but not all) modules included this way, I think for this particular use case another approach is needed besides what I did here -- probably dynamically generating paths config. So, please disregard -- closing this thread for now!