Tree shaking with TSDX - typescript with rollup

852 views Asked by At

I have a Monorepo which is created using yarn workspaces and bundled with TSDX.

Note: TSDX is Typescript + Rollup

My Monorepo has 2 folders inside packages,

  • App (private) - It's a CRA - create react app application, this application is consuming Components package
  • Component - It's a package using TSDX for bundling

Component package has 3 components exported

  • logOne
  • logTwo
  • FilePreviewer Note : FilePreviewer component is using a external package (react-pdf)

Exported file from components package has following code

export function logOne () {
  return "Rendered logOne()";
}
export function logTwo() {
  return "Rendered logTwo()";
}

export * from "./filePreviewer";

I'm importing only logTwo() inside App,

Expected behavior App should have only logTwo,

Actual behavior logTwo and it is importing FilePreviewer dependent package (react-pdf)

I have created a public Github repository to replicate above scenario, Click here for Github repository link

STEPS TO FOLLOW

  • Clone the repository
  • yarn install
  • yarn build - build Component package
  • yarn start - start App package
  • yarn analyze - analyze the build and show bundle size
0

There are 0 answers