Convert URL to require or import sytanx in JSX.
<img src="/static/image.jpg" />
<link rel="stylesheet" href="/static/style.css" /><img src={require("/static/image.jpg")} />
<link rel="stylesheet" href={require("/static/style.css")} />npm install --save-dev babel-plugin-transform-jsx-urlWithout options:
{
"plugins": ["transform-jsx-url"],
}With options:
{
"plugins": [
["transform-jsx-url", {
"root": "/src",
"attrs": ["img:src", "img:data-src", "link:href"],
}],
],
}string, defaults to "".
If a root query parameter is set, however, it will be prepended to the url and then translated.
"root": "/src"
<img data-src="/static/image.jpg" /><img data-src={require("/src/static/image.jpg")} />Array, defaults to ["img:src", "link:href"] .
You can specify which tag-attribute combination should be processed by this loader. Pass an array or a space-separated list of : combinations.
"attrs": ["img:data-src", "custom:src"]
<img data-src="/static/image.jpg" />
<custom src="/static/image.jpg" /><img data-src={require("/static/image.jpg")} />
<custom src={require("/static/image.jpg")} />