-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: external editor #983
Comments
@Mikescops all prompts are now available as standalone packages. If size is a concern, you can use those directly and not have the editor prompt in your dependencies. |
@SBoudrias Thanks for the answer, I'll follow this recommandation, but what bugs me is that the main package is supposed to be an ESM so the tree shaking should not take into account the editor prompt and its dependencies if I don't use it. |
@Mikescops which package are you using today? In the way It should in the new packages, you can see the package content on npm - it does ship pure ESM. But it's a dual module format package, so make sure your build chain doesn't end up importing the CJS versions. |
@SBoudrias I'm using In my code i only have this Here is the chain that is happening: |
Are you sure your build tool should/would tree-shake that? Here it just shows it follows all import, so it doesn't get treeshake. Not sure where it's coming from... Does it require the whole tree to be ESM to treeshake? |
I'm using esbuild which is a well known bundler, and they have tree shaking: https://esbuild.github.io/api/#tree-shaking From their documentation:
I'm trying to poc around to see if I miss something obvious. |
Well, I've played with different things but I can't figure out what's going on. I'll use the initial solution of only adding the sub dependencies I need. |
@SBoudrias I figured out overnight what's going on. I was reading a nice blog post about how tree shaking works: https://blog.jetbridge.com/mastering-javascript-tree-shaking/ And I read the part around side effects, that is also mentioned in the documentation of esbuild: https://esbuild.github.io/api/#tree-shaking-and-side-effects I didn't understood at the beginning what it exactly meant but this quote helped: So I gave it a try with the editor module: {
"name": "@inquirer/editor",
"version": "2.1.8",
"description": "Inquirer multiline editor prompt",
"main": "./dist/cjs/index.js",
"typings": "./dist/cjs/types/index.d.ts",
"files": [
"dist/**/*"
],
"sideEffects": false,
} And 🎉
I assumed here that your package doesn't have any "side effects". If that's true and if you agree, I think marking your sub dependencies as |
Thanks, I'll add that field in! |
Merci @SBoudrias ! 💪 |
I helped the maintainer of inquirer improve the package so it supports tree shaking with ESM: SBoudrias/Inquirer.js#983 (comment)
I have been reviewing code base, and i'm trying to figure out what is purpose of editor package as prompt for it is implemented directly in inquirer because of that, even if user does not plan to use this feature is required to include
iconv-lite
iconv-lite is a huge package and in comparison to library size its~40% of this project
Inquirer.js/packages/inquirer/package.json
Line 44 in ca70e03
Inquirer.js/packages/inquirer/lib/prompts/editor.js
Line 12 in ca70e03
shouldn't this be moved to to editor package?
The text was updated successfully, but these errors were encountered: