Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can i use <img src='xxx.png'> without require? #196

Closed
BaronJHYu opened this issue Nov 1, 2021 · 2 comments
Closed

How can i use <img src='xxx.png'> without require? #196

BaronJHYu opened this issue Nov 1, 2021 · 2 comments
Labels

Comments

@BaronJHYu
Copy link

image
image

only ‘require’ usable. Is it some wrong with svelte-loader?

@BaronJHYu
Copy link
Author

or how can i config to make it usable?

@mcuppi
Copy link

mcuppi commented Jun 2, 2022

@BaronJHYu If I understand your question correctly, you're asking why src="../images/close.png" fails, but src={closePic} works.

The reason the latter example works is because you make Webpack "aware" of the asset. By importing the image, you're defining an explicit dependency. This allows Webpack to "see" the asset and handle it according to the rules you defined in the configuration file.

Webpack won't be able to manage your assets if you just reference them as string somewhere in your code (e.g., src="../images/close.png"). As far as I understand, Webpack doesn't automatically parse through all of your code in an attempt to find strings that look like asset URLs.

For more information about asset management, please refer to Webpack's asset management documentation.

@dummdidumm; I believe this issue should be closed as I'm fairly confident this question has more to do with Webpack than svelte-loader. Additionally, if we want to track this as a feature request, #114 would probably be a better issue to use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants