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

Add a single-file component (SFC) format #3965

Open
AllanOricil opened this issue Jan 31, 2024 · 2 comments
Open

Add a single-file component (SFC) format #3965

AllanOricil opened this issue Jan 31, 2024 · 2 comments

Comments

@AllanOricil
Copy link
Contributor

AllanOricil commented Jan 31, 2024

Is your feature request related to a problem? Please describe.
I was reading some vue docs and started to think:

  • why isn't there a .lwc file extension?
  • why can't I declare my .html, .js and .css in a single file?
  • wouldn't It be cool to have .lwc files be represented with a lightning icon on code editors?
  • it is so much easier to create and write a single file than 1 folder and, up to, 3 files. Don't you agree?

Describe the solution you'd like
I would like to be able to create lwc components declaring .html, .css and .js in a single file called my-component.lwc, like in Vue or Svelte.

<template></template>
<script></script>
<style></style>

<!-- meta: platform specific metadata-->
<metadata></metadata>

Describe alternatives you've considered
There isn't an alternative.

Additional context
N/A

@nolanlawson nolanlawson changed the title Create the .lwc file extension Add a single-file component (SFC) format Jan 31, 2024
@nolanlawson
Copy link
Collaborator

Thanks for opening the issue! This is something we've discussed internally, but haven't committed to implementing. Metadata would probably not be included, but having the template/script/style in one file is something we've considered.

/cc @rui-rayqiu

@AllanOricil
Copy link
Contributor Author

AllanOricil commented Feb 1, 2024

Did you guys discuss about support that feature that allows a component to have multiple templates, and choose 1 to render at a time based on the render method response? It would be nice if we could still use multiple <template> when using a single file.

You could require a boolean variable in all other templates. The ones without it is the default one. There could exist only 1 without a boolean expression.

<template></template> <!--default-->
<template render={renderA}>A</template>
<template render={renderB}>B</template>


<script>
...
function renderA(){...}
function renderB(){...}
...
</script>

If more than 1 template is due to be rendered at the same time, then throw an exception.

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

No branches or pull requests

2 participants