Skip to content

Convert image relative path to dynamic require expression? #1297

Answered by ChristianMurphy
dpyzo0o asked this question in Q&A
Discussion options

You must be logged in to vote

@dpyzo0o without seeing the actual transform, it's hard to comment on what works/doesn't.

In terms of creating a plugin/transform, use the input and the output as a guide.
You want to go from:

![description](./image.jpg)

to

<img alt="description" src={require("./image.jpg")} />

so look at the two ASTs and transform one to the other https://astexplorer.net/#/gist/b83785f495e910aaa71d631699d5c964/54ba6104c2b206f5805951c6736536f528ea7c25

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@dpyzo0o
Comment options

@dpyzo0o
Comment options

@dpyzo0o
Comment options

Answer selected by dpyzo0o
Comment options

You must be logged in to vote
2 replies
@wooorm
Comment options

@lucastobrazil
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants