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

Allow src in <script setup> #219

Closed
customautosys opened this issue Oct 18, 2020 · 3 comments
Closed

Allow src in <script setup> #219

customautosys opened this issue Oct 18, 2020 · 3 comments

Comments

@customautosys
Copy link

Hi, I don't understand the rationale for disallowing scripts to be placed in an external file for <script setup>. Even normal scripts depend on the component's context and yet there is no such restriction. I like to separate my css, html & js by using vue-builder-webpack-plugin. Why can't you allow <script setup> to have an src attribute?

@yoyo930021
Copy link
Member

Hi, I don't understand the rationale for disallowing scripts to be placed in an external file for <script setup>. Even normal scripts depend on the component's context and yet there is no such restriction. I like to separate my css, html & js by using vue-builder-webpack-plugin. Why can't you allow <script setup> to have an src attribute?

If you put code outside Vue SFC file, we can't provide any development experience.
Like ref-sugar #222, You will get many error in IDE.

@yyx990803
Copy link
Member

Aside from IDE support, <script setup> content is not actually module scope. It is compiled to be wrapped into a function and re-invoked per component instance. The semantics would be incorrect in a standalone js file - e.g. you can't use ES module import/export from it.

If you simply like having the parts in different editor tabs, you can open the same file in different tabs and scroll to different parts (not sure about other IDEs but VSCode can do that just fine)

@jods4
Copy link

jods4 commented Nov 24, 2020

I wanted to support this issue at one point, then changed my mind back and forth a few time.

If you simply like having the parts in different editor tabs, you can open the same file in different tabs and scroll to different parts (not sure about other IDEs but VSCode can do that just fine)

To me it wasn't about having two views in the IDE. It was more about splitting large components into smaller parts. With other frameworks I was used to having the code and the template in two files next to each other (it was the only way).

I saw the problems though, and came to the conclusion that you can always put code in separate files and import it into your <script setup>. You still benefit from variables export, automatic component and directive registration, nice TS props typing.

👉 To me that suggests that "code writing" improvements shouldn't be limited to <script setup>. Splitting large components into files shouldn't mean giving up on potential auto unref'ing or auto async context flow.

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

No branches or pull requests

4 participants