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

Global API Treeshaking #19

Merged
merged 5 commits into from
May 30, 2019
Merged

Global API Treeshaking #19

merged 5 commits into from
May 30, 2019

Conversation

yyx990803
Copy link
Member

@yyx990803 yyx990803 added breaking change This RFC contains breaking changes or deprecations of old API. core 3.x This RFC only targets 3.0 and above labels Mar 1, 2019
@yyx990803 yyx990803 changed the title global api treeshaking proposal Global API Treeshaking Mar 1, 2019
@laander
Copy link

laander commented Mar 12, 2019

Would this also apply to more core concepts such as Vue.extend?

Instead of:

import Vue from 'vue'

Vue.extend({
  ...
})

We would do:

import { extend } from 'vue'

extend({
  ...
})

@yyx990803
Copy link
Member Author

yyx990803 commented Mar 13, 2019

@laander extend is probably going to be an exception and kept on Vue itself. The code for internal class extension is going to be included in any app anyway.

@phanan
Copy link
Member

phanan commented Mar 13, 2019

Note the above only applies to the ES Modules builds for use with tree-shaking capable bundlers - the UMD build still includes all features and exposes everything on the Vue global variable (and the compiler will produce appropriate output to use APIs off the global instead of importing).

When it all makes sense, I'm a bit concerned when it comes to documentation. How would we present both modules and UMD APIs in our examples? Off the top of my head, we can:

  1. Use a tabbed interface for the examples, with each tab using the corresponding API/syntax, or
  2. Only use one of the two for the examples, with the other documented somewhere

IMHO 1 is better, but I'm not sure about the maintenance method and whether it can be automated.

@laander
Copy link

laander commented Mar 13, 2019

@yyx990803 I assume that everything that registers on/interacts with the global Vue instance can't be extracted, right? E.g.
Vue.directive
Vue.filter
Vue.component
Vue.mixin
Vue.use

@yyx990803
Copy link
Member Author

@laander these are APIs that globally mutate the Vue constructor and will likely be re-designed (which will have its own RFC).

@clemyan
Copy link

clemyan commented Apr 11, 2019

Naming the function that creates VNodes as h is (as far as I can see) a legacy of Vue 2.x, where it is passed as an argument to the render function and the consumer can choose any variable name for it.

With ES modules, we can export the function under any name while the importer is still free to rename it anything. So, IMO, we should export it under a more descriptive name like createVNode and encourage the convention import { createVNode as h } from 'vue'.

This would be invisible to users writing templates or JSX (since the import statement is generated by the compiler anyway) and communicate more clearly to render function writer what the function is doing.

yyx990803 added a commit that referenced this pull request Apr 11, 2019
@yyx990803
Copy link
Member Author

yyx990803 commented Apr 11, 2019

@clemyan I like that. See fb11b66 (note createVNode is in fact something lower-level that exists internally, the public one should be createElement to be precise)

@yyx990803 yyx990803 merged commit c865aa8 into master May 30, 2019
@agronick
Copy link

I'm in favor of exporting as much as possible. The other day I was trying to import supportsPassive and found that it couldn't be done. The only way to find out if the browser supported passive event handlers was to duplicate the same logic already built into Vue.

@onx2
Copy link

onx2 commented Mar 3, 2020

If a codebase only uses the Composition API, is the Options API something that is tree-shaken?

@yyx990803
Copy link
Member Author

@onx2 by default it cannot, because we cannot predict what options the users will use. But there will be a compile-time flag to drop it.

@yyx990803 yyx990803 added the feat: global api Changes related to global API label Jul 1, 2020
@bencodezen bencodezen mentioned this pull request Jul 6, 2020
25 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x This RFC only targets 3.0 and above breaking change This RFC contains breaking changes or deprecations of old API. core feat: global api Changes related to global API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants