Ability to extend the cli
See original GitHub issueClear and concise description of the problem
I’m currently creating a SSR plugin for Vite, I would like to give the user the ability to start the server as SPA mode too.
But if I run something like vite --spa
will give an error:
throw new CACError(`Unknown option \`${name.length > 1 ? `--${name}` : `-${name}`}\``);
Suggested solution
just add a cli
option to the Plugin
interface, pass the vite
cli object to it, this pseudocode shows it adds an additional option to the serve
command.
{
name: 'foo',
cli(cli: CAC) {
const serveCommand = cli.commands.find(({name})=> name==='[root]')
serveCommand.option('--spa', `start dev server in SPA mode`)
}
}
I’ve been saw lots of plugin creators create a separated cli just for there plugin, it really should be a part of the vite
command itself, this way, fits so natural and saving time, plus giving a change to add additional options to the default commands.
What you guys think about this?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Extending the CLI | OpenShift Container Platform 3.11
Overview. This topic reviews how to install and write extensions for the CLI. Usually called plug-ins or binary extensions, this feature allows you...
Read more >How to install and manage Azure CLI extensions
With extensions, you gain access to experimental and pre-release commands along with the ability to write your own CLI interfaces. This article ...
Read more >How To Make Your CLI More Intuitive - Nordic APIs
Here are some ways to improve the CLI experience. ... increase the user's ability to reason, understand, and extend their interactions.
Read more >What is a command-line interface (CLI)? - TechTarget
A command-line interface (CLI) is a text-based user interface (UI) used to run programs, manage computer files and interact with the computer.
Read more >How to extend a disk in Windows using diskpart - Qualitest
You can extend the size of the space allocated to the OS. Requirements: Access to the Windows command line, and optionally a file...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If we allow extending the vite cli, we need to start thinking about possible collisions with future features. At this point, I agree that it is better to avoid the extra complexity in core. You could create an extensible-vite package to be used by others if they think that this approach has merits.
I find there is a “allowUnknownOptions” property in vite/dist/node/cli.js. And it used at
I tried change the code vite/dist/node/cli.js as following:
Add a allowUnknownOptions() call after command init method, then the vite build command will ignore unknown args.
But how can I set allowUnknownOptions to true do not change the source code? Because I want to pass some args to my vite plugin.