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 inlibrary 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
- Running
app-vite
- This directory is a standard vite app, which useslib-vite
- The
lib-vite-0.0.0.tgz
created by thelib-vite
build/pack process is copied into this directory and installed into the app
- The
app-cli
- This directory is a standard vue cli app- The
lib-vite-0.0.0.tgz
created by thelib-vite
build/pack process is copied into this directory and installed into the app
- The
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.
Setup
- Clone repo
- Inside the
lib-vite
directory, runnpm install
, followed bynpm run build && npm pack
- this will create the filelib-vite-0.0.0.tgz
- Copy the resulting
lib-vite-0.0.0.tgz
into each app directory (app-vite
andapp-cli
) - In each app directory:
- Run
npm install
followed bynpm run build
- Run
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.
Code output should be tree-shakeable
Code is not tree-shakeable