You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Build executable CLI script in library mode. #18871
It would be great to have an ability to build CLI script starting with a hashbang:
#!/usr/bin/env node
// parse arguments...
Many libraries offer CLI scripts; in fact, many libraries are CLI scripts. Vite has a useful library mode, and the ability to build a CLI companion alongside a browser-oriented library would be a valuable addition.
Suggested solution
As an example, it can be enabled using the entryCli library mode option.
Yep, it may be executable by default for files with hashbangs. Additionally, the CLI distribution must be compiled in the correct format. I attempted to create a separate vite.cli.config.ts to build the CLI script.
Activity
sapphi-red commentedon Dec 4, 2024
If you put
#!/usr/bin/env nodein your entry point, Vite will keep that as-is. So you don't need to set any option.I think we can set
+xfor all output entrypoints with a hashbang.slavarazum commentedon Dec 4, 2024
Yep, it may be executable by default for files with hashbangs. Additionally, the CLI distribution must be compiled in the correct format. I attempted to create a separate vite.cli.config.ts to build the CLI script.
Reproduce example
https://stackblitz.com/edit/vitejs-vite-5qfsan?file=vite.cli.config.ts
will throw:
Caution
Error: Class extends value undefined is not a constructor or null
the same for
cjsformat.We can see how it works in comparison with
tsup:egasimus commentedon Nov 22, 2025
sapphi-red commentedon Nov 26, 2025