Skip to content

Why&How tree-shaking this code after build? #19063

Answered by sapphi-red
Yuliang-Lee asked this question in Q&A
Discussion options

You must be logged in to vote

The easier way would be to separate the file and avoid importing the parts that is not needed in the front-end side.
For example, extract the enums in a separate file called src/git_submodule/typeorm/enums.ts and import that file from the front-end side and src/git_submodule/typeorm/test.ts.

The harder way would be to tell rollup the statements as side-effect free. In this case, import 'typeorm' and @Entity('t_test', { schema: 'db_a' }) call is assumed as side-effectful. For the former one, you can set build.rollupOptions.treeshake.moduleSideEffects: (id) => { if (id === 'typeorm') { return false } }. For the latter one, you can wrap it with IIFE and mark it with #__PURE__.

export const T…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Yuliang-Lee
Comment options

Answer selected by Yuliang-Lee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants