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

compile script setup components to components with setup() returning a render function #12847

Open
jacekkarczmarczyk opened this issue Oct 23, 2022 · 1 comment

Comments

@jacekkarczmarczyk
Copy link

What problem does this feature solve?

Currently script setup components are compiled to a code where setup() function returns all data used in the template, components have also components property like you'd define it in normal script.

In Vue 3 setup() returns a render function that is accessing local variables and imported components directly which results in a smaller size of the bundle not only because of shorter code before minification but also because all variable and component names can be shortened to single letters. Would be great if Vue 2 behaved the same way, maybe some compiler configuration option could be used to force this?

What does the proposed API look like?

{
      __name: 'MyComponent',
      props: { prop1: Object, prop2: Boolean },
      setup (s) {
        const e = s, d = whatever();
        return () => h(a.B, ...)
      }
    }

instead of

{
      __name: 'MyComponent',
      components: { Foo: a.B, Bar: c.d },
      props: { prop1: Object, prop2: Boolean },
      setup (s) {
        const e = s, d = whatever();
        return { __sfc: !0, props: e, someData: d };
      }
    }
@yyx990803
Copy link
Member

This is currently a non-goal because Vue 2's template-to-render-fn compilation was written in a way that does not perform any JS expression parsing (it is done in a separate pass with other tools). So the whole process does not have the necessary information to prefix/unwrap refs based on <script setup> scope information. This is only possible if we completely rework Vue 2's template compilation, but that would be a big and risky refactor which we for now don't plan to do.

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