Base URL
Define a string that will be prepended to all sources and hrefs in your HTML and CSS. Useful if you already host your images somewhere like a CDN, so you don’t have to write the full URL every time when developing. Works with the following HTML attributes:- src
- href
- srcset
- poster
- background
background: url()background-image: url()@font-face { src: url() }
<style> tags and style="" attributes are supported. CSS property values with multiple url() sources (like @font-face declarations) are supported as well.
Usage
Make it globally available by setting it in your environment config:config.js
Customization
You’ll most likely want to customize the transformer so that it applies only to certain elements, or even only to certain attributes of certain elements.tags
Apply the base URL only to specific tags.
<img> tags:
config.js
url to all known source attributes on all <img> elements in your HTML, like src="" or srcset=".
If you need greater control, you may specify which attributes of which tags should be prepended what URL, by passing in an object instead:
config.js
attributes
Key-value pairs of attributes and what to prepend to them.
config.js
styleTag
By default, the transformer will prepend your
url to all url() sources in <style> tags. Set this option to false to prevent it from doing so.config.js
inlineCss
Similarly, the transformer will prepend your
url to all url() sources in style="" attributes. You may disable this if you need to.config.js
Front matter
You may override it for a single Template, through Front Matter:emails/example.html
Trailing slash
WhenbaseURL is not an absolute URL, path.join is used to prepend the base URL to the source, so you don’t need to worry about trailing slashes.
However, you need to consider trailing slashes when the base URL is an absolute URL.
baseURL:
baseURL, we get a double slash in the result:
baseURL:
Disabling
If you havebaseURL set globally (in your config), you may disable it for a Template by setting its value to an empty string or a falsy value in Front Matter:
API
app.js