You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: active-rfcs/0004-global-api-treeshaking.md
+7-7
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ Make Vue runtime tree-shakable by exposing as much APIs through named exports as
9
9
10
10
# Basic example
11
11
12
-
```js
12
+
```js
13
13
import { nextTick, observable } from'vue'
14
14
15
15
nextTick(() => {})
@@ -29,7 +29,7 @@ In addition, knowing that optional features won't increase the bundle size for u
29
29
30
30
Currently in 2.x, all global APIs are exposed on the single Vue object:
31
31
32
-
```js
32
+
```js
33
33
importVuefrom'vue'
34
34
35
35
Vue.nextTick(() => {})
@@ -39,7 +39,7 @@ const obj = Vue.observable({})
39
39
40
40
In 3.x, they can **only** be accessed as named imports:
41
41
42
-
```js
42
+
```js
43
43
importVue, { nextTick, observable } from'vue'
44
44
45
45
Vue.nextTick// undefined
@@ -64,7 +64,7 @@ By not attaching all APIs on the `Vue` default export, any unused APIs can be dr
64
64
65
65
In addition to public APIs, many of the internal components / helpers can be exported as named exports as well. This allows the compiler to output code that only imports features when they are used. For example the following template:
66
66
67
-
```html
67
+
```html
68
68
<transition>
69
69
<divv-show="ok">hello</div>
70
70
</transition>
@@ -86,15 +86,15 @@ This means the `Transition` component only gets imported when the application ac
86
86
87
87
**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).**
88
88
89
-
# Drawbacks
89
+
# Drawbacks
90
90
91
91
Users can no longer import a single `Vue` variable and then use APIs off of it. However this should be a worthwhile tradeoff for minimal bundle sizes.
92
92
93
93
## Global API usage in plugins
94
94
95
95
Some plugins may rely on global APIs originally exposed on `Vue`:
0 commit comments