1

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 !

2
  • You don't need node_modules here, just import Comp from '@mylib/.../Comp.vue'. It should be the same size if it's ES module Commented Sep 20, 2023 at 8:34
  • import Comp from '@mylib/entrypoint' is already shorthand for import Comp from 'node_modules/@mylib/entrypoint'. There is no difference. Commented Sep 20, 2023 at 21:11

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.