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

fix(treeshaking): allowing tree-shaking with terser #74

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Commits on Jan 12, 2023

  1. 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, 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 component code.
    
    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__)
    ```
    Adam Hines committed Jan 12, 2023
    Configuration menu
    Copy the full SHA
    3c2f6b9 View commit details
    Browse the repository at this point in the history