-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
feat(sfc): allow multiple template and script blocks in a SFC #7264
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
Conversation
This is great! |
@posva We could add a name attribute, but that would limit us with syntax, unless we auto-generate a name ( <template></template> <!-- default -->
<template name="native"></template> But I still think it is nicer to have / write like so <template web></template>
<template native></template> |
The reason I'm proposing an attribute with a value is because it doesn't make sense to write |
Can't we solve the problem from the build layer i.e. having multiple files ( |
That's a valid point, but I would leave that to the tool to validate what should / shouldn't be possible
Sure we can, but I would leave this up to the tool / loader to decide. For example we plan on doing more than just compiling one (edit: fixed formatting) |
I personally feel the syntax is less maintainable than @phanan 's suggestion. What I'd personally do is: - Foo.web.vue
- Foo.native.vue
- Foo.shared.js # shared between web and native
- Foo.shared.scss # shared between web and native The shared js can be imported by both The shared CSS can be SASS mixins or whatever reuse mechanism the pre-processor allows. Again, can be done automatically. Note that we want to keep the SFC syntax as consistent possible, because it involves a big ecosystem of tools that need to support any new features added (e.g. Vetur would need to do something very different for handling SFCs with multiple scripts/templates). The proposed syntax, IMO, does not justify adding the new syntax. |
I do understand that there is a big ecosystem around SFC syntax, although I do not think this addition would require all the tooling to support it, since there are no breaking changes. It would only allow us to experiment with the new syntax in our own loader implementation without maintaining a fork of the parser. We will keep experimenting with the proposed syntax using my fork, to see how it works out in the real world. Thanks for your feedback! |
@rigor789 yeah, I think exploring in a fork would be a plausible step for now, we can revisit this with more real world feedback. |
@yyx990803 Absolutely! Thanks |
is there any repo for this? |
What kind of change does this PR introduce? (check at least one)
Does this PR introduce a breaking change? (check one)
If yes, please describe the impact and migration path for existing applications:
The PR fulfills these requirements:
dev
branch for v2.x (or to a previous version branch), not themaster
branchfix #xxx[,#xxx]
, where "xxx" is the issue number)If adding a new feature, the PR's description includes:
Other information:
The reason I'm submitting this PR is because for
nativescript-vue
we would like to introduce code-sharing between web and native, but one limiting factor is that we can't have more than 1template
orscript
tag in a SFC.We would like to write our SFC like so:
(More information can be found at tralves/ns-vue-loader#2)
The current implementation assumes only 1 of these blocks, and only the last one is kept, with this PR it will parse all of the blocks, and return them in an array, while keeping it backwards compatible.