0

At my workplace, we have dev and production environments, and a separate server that serves static files for each environment. In my code, I make references to the URL of this static file server. Manually switching the references between servers would be a large chore, so I'm trying to incorporate a gulp task into my automation strategy, but I'm running into an issue.

Some of my code is already using Underscore templates, so using a templating library with gulp creates ambiguity on which code should be compiled through gulp and which code should be ignored.

In our environment, we refer to servers that serve static files as "image servers".

For example, I have a script tag that looks like this:

<script src="<%= image_server_url %>/scripts/iep-alert/alert.js"></script>

All I need is simple string interpolation in this case. However, I get errors from other template code in the project that certain variables are not defined because the context in which the gulp template task is operating with is different from the context that I pass the template when it is referenced within a browser.

So, what's the best (or sufficient) way to dynamically set the URL to my static file server throughout my project? Is it with gulp, am I missing a plugin I should be using? If so, how do I tell gulp to ignore certain templates?

I have asked a similar, more code-centric version of this question on StackOverflow.

1

I ended up using the gulp-preprocess plugin. My code looks like this now and it's working well so far.

<script src="<!-- @echo IMAGE_SERVER_URL -->/scripts/iep-alert/alert.js"></script>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.