How to import from a vue3 lib

31 Views Asked by At

I'm creating a big big vue 3 library with Vite and Typescript. I'm trying to have the most optimized app for the final build. I don't understant whats the difference beetween importing from the lib or directly the file from the lib.

Like for example, it is better to import like that : import Comp from '@mylib/entrypoint' Or like that : import Comp from 'node_modules/@mylib/.../Comp.vue'

I've tried both and I seem to win some little kb with the second method but i dont know if it is worth the price, can somebody explain please thanks !

1

There are 1 best solutions below

0
Suresh Kumar Gangumallla On

In general the entrypoint (index.js) responsible for exporting all exportable functions from particular library. One should avoid importing particular module by travelling deep into origin file to import that module. Library might have different modules based on it's architecture but at the end library entry point imports all different modules and re export them. so I suggest always import modules from entry point.