Relative Content

Tag Archive for javascripttypescriptimageurlparcel

How to add URL Dependencies dynamically using Parcel?

Problem: I use Parcel as a bundler of my project and try to inject HTML markup into my index.html from my TypeScript file. Injected markup contains <img> elements with dynamically resolved paths for their src attribute. The paths I’m trying to add to the images’ src attributes are stored as properties of my data.json file, which I import directly into my TypeScript file. The problem is that Parcel support only string literals inside new URL() syntax, therefore I don’t know how to use template literals/variables inside this function to add dynamic URL dependencies.