Subscribe on changes!

Template breaks asterisk tree-shaking?

avatar
Jan 5th 2022

Version

3.2.26

Reproduction link

stackblitz.com

snap

Steps to reproduce

  1. Import module with asterisk, import * as tree from './tree-shaking2'
  2. Use imported var in template {{ tree.used2() }}
  3. Build with vite build
  4. Checkout output files

What is expected?

Only tree.used2() will be found in bundle

What is actually happening?

All exports from 'tree-shaking2.ts', even those not used, like tree.notUsed2() will be present in bundle.


Dig in sfc compiler.

Possible cause:

  • Compiler detects tree as maybeRef, hitting the unref logic.
  • tree.used2() turns into unref(tree).used2().
  • The unref() call breaks tree shaking.