Replace remote file paths
jabranr opened this issue · 2 comments
It would be great to have an option where remote paths can be replaced with their alternatives. There are few example of such cases as follow:
Usage:
- Consider the use of readable Bootstrap in dev environment and minified Bootstrap in production environment.
<!-- dev -->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.css">
<!-- production -->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
- Consider the use of URLs that require an API key in production environment i.e. Google Maps API. The ideal use would be to use the basic URL for API calls in dev environment and then a modified URL with API key in production environment.
<!-- development -->
<script src="//maps.googleapis.com/maps/api/js?v=3&sensor=false"></script>
<!-- production -->
<script src="//maps.googleapis.com/maps/api/js?v=3&sensor=false&key=123456789"></script>
Current status:
HTML:
<!-- build:remote:js http://maps.googleapis.com/maps/api/js?v=3&sensor=false&key=123456789 -->
<script src="http://maps.googleapis.com/maps/api/js?v=3&sensor=false"></script>
<!-- endbuild -->
Expected:
<script src="http://maps.googleapis.com/maps/api/js?v=3&sensor=false&key=123456789"></script>
Actual:
>>> Destination dist/http:/maps.googleapis.com/maps/api/js?v=3&sensor=false&key=123456789
not written because src files were empty.
Suggestion:
<!-- build:remote:js //maps.googleapis.com/maps/api/js?v=3&sensor=false&key=123456789 -->
<script src="//maps.googleapis.com/maps/api/js?v=3&sensor=false"></script>
<!-- endbuild -->
<!-- build:remote:css //maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css -->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.css">
<!-- endbuild -->
Thanks 👍
@jabranr I suggest you give a shot to grunt-preprocess or other alternatives. It's not the job of usemin. Usemin is already a quite complex piece of software and it's purpose is to minify all your content and replace all the assets url with a revved one.
Your problem is to support different url for dev and prod which is not usemin job.
@stephanebachelier OK thank you! I thought I was talking about replacing assets URLs, just not with revved ones. :) But appreciate your reply to this issue.
However I have actually found one of the usemin options (blockReplacements) for such a use case. An implementation of such case can be found in one of my recent project at:
- https://github.com/jabranr/guess-where/blob/gh-pages/Gruntfile.js#L158
- https://github.com/jabranr/guess-where/blob/gh-pages/app/index.html#L87
- https://github.com/jabranr/guess-where/blob/gh-pages/app/index.html#L106
I would imagine this issue resolved now with this alternative use.