8000 feat(compiler-sfc): transform asset url by underfin · Pull Request #500 · vuejs/core · GitHub
[go: up one dir, main page]

Skip to content

feat(compiler-sfc): transform asset url #500

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

Merged
merged 3 commits into from
Dec 1, 2019

Conversation

underfin
Copy link
Member

No description provided.

@yyx990803
Copy link
Member
yyx990803 commented Nov 26, 2019

The reason I left them as TODO is because we probably want to redo this to use import instead.

For example, currently

<img src="./logo.png" srcset="./logo.png"/>

is compiled to:

createVNode('img', {
  src: require("./logo.png")
})

But inline require is somewhat a legacy thing in webpack now. The more ideal output would be:

import logoPng from './logo.png'

createVNode('img', {
  src: logoPng
})

So, instead of generating an inline require call, we need to inject an import statement at the top of the generated code. To do this we need to

  1. Change urlToRequire to urlToImport;
  2. Add a method to TransformContext and handle it accordingly in codegen.

@underfin underfin force-pushed the transformAssetUrl branch 4 times, most recently from d61afe5 to 9fd5b51 Compare November 28, 2019 13:23
@yyx990803 yyx990803 merged commit 810b3a3 into vuejs:master Dec 1, 2019
@yyx990803
Copy link
Member

👍

@vue-bot
Copy link
Contributor
vue-bot commented Dec 1, 2019

Hey @underfin, thank you for your time and effort spent on this PR, contributions like yours help make Vue better for everyone. Cheers! 💚

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

Successfully merging this pull request may close these issues.

3 participants
0