3

Is there a way to replace variables with gulp inside HTML? In my case, I have development HTML files where are paths for images, for e.g. /assets/img/*.jpg, but in production file I need those paths replace with ones which the CMS generates after file uploads. They are completely different and there isn't logic in folder names for e.g. /12365/586/*.jpg.

Im looking for:

  • gulp task to replace and generate HTML for development
  • gulp task to replace and generate HTML for production

Dev HTML

variable_name_dev = "/assets/img"
variable_name_prod = "/12365/5698"

<img src="variable_name/bg.jpg" alt="Smiley face">

Generated Dev HTML

<img src="/assets/img/bg.jpg" alt="Smiley face">

Generated Production HTML

<img src="/12365/5698" alt="Smiley face">

1 Answer 1

3

How about gulp-inline-image-path? Or I've used gulp-token-replace for similar scenarios.

Sign up to request clarification or add additional context in comments.

1 Comment

gulp-token-replace works like a charm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.