Commit 2f53050
Adam Hines
fix(treeshaking): allowing treeshaking in terser
The code currently generated by this plugin looks something like the following when building a library:
src/index.js
```js
export {default as Foo} from './component.vue';
```
```js
var __component__ = /*#__PURE__*/ normalizeComponent(...)
var Foo = __component__.exports
```
In the event you aren't actually using the Foo export, using a minifier like Terser, this code is unable to be dropped because Terser assumes that property access (__component__.exports) is not side-effect free and as a result it decides it can not drop it, and thus it can't drop the rest of the components.
To work around this, I have wrapped the `__component__.exports` statement in a function so that we can mark the function invokation as `#__PURE__` and thus allow for unused components to be dropped fully.
The resulting code looks like:
```js
var __component__ = /*#__PURE__*/ normalizeComponent(...)
var Foo = /*#__PURE__*/ getExports(__component__)
```1 parent ad7d61e commit 2f53050
2 files changed
+10
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
| 77 | + | |
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
140 | | - | |
| 140 | + | |
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
8 | 15 | | |
9 | 16 | | |
10 | 17 | | |
| |||
0 commit comments