Skip to content

mgdodge/vue-compiler-treeshaking-bug

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Vue 3 tree-shaking bug

This repo is organized as follows:

  • lib-vite - This directory is the source for what should be a tree-shakeable component. It uses vite 2.6.0-beta.2 in library mode to create the library package
    • Running npm run build && npm pack here results in an installable npm module, lib-vite-0.0.0.tgz
  • app-vite - This directory is a standard vite app, which uses lib-vite
    • The lib-vite-0.0.0.tgz created by the lib-vite build/pack process is copied into this directory and installed into the app
  • app-cli - This directory is a standard vue cli app
    • The lib-vite-0.0.0.tgz created by the lib-vite build/pack process is copied into this directory and installed into the app

The library and the sample apps use the default output from npm init vite or vue create. The library uses the recommended configuration from the vite docs for library mode.

Reproducing the bug

Setup

  • Clone repo
  • Inside the lib-vite directory, run npm install, followed by npm run build && npm pack - this will create the file lib-vite-0.0.0.tgz
  • Copy the resulting lib-vite-0.0.0.tgz into each app directory (app-vite and app-cli)
  • In each app directory:
    • Run npm install followed by npm run build

Verify tree-shaking

The "optimized" javascript resulting from each build will include a "vendors" file which should include a tree-shaken version of lib-vite. Search this file for the following strings:

"The cat is named"
"The dog is named"
"The fish is named"

If tree-shaking worked, you should not see The fish is named anywhere in the output. The unused code is still included.

What is expected?

Code output should be tree-shakeable

What is actually happening?

Code is not tree-shakeable

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published