Skip to content
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

Update CLI to Allow Specifying Vite Config Location #156

Open
MichealPearce opened this issue Apr 10, 2022 · 1 comment
Open

Update CLI to Allow Specifying Vite Config Location #156

MichealPearce opened this issue Apr 10, 2022 · 1 comment

Comments

@MichealPearce
Copy link

MichealPearce commented Apr 10, 2022

The vite cli allows specifying the location of the config via the command using -c or --config. Currently, vite-ssr does not allow this without a workaround by using --configFile instead. This could be fixed and make vite-ssr more inline with vite's cli command by updating the bit of code linked below to look for -c or --config and mapping it to configFile.

vite-ssr/src/cli.ts

Lines 14 to 21 in fad2ca8

for (let i = 0; i < args.length; i++) {
const arg = args[i]
const nextArg = args[i + 1]
if (arg.startsWith('--')) {
options[arg.replace('--', '')] =
!nextArg || nextArg.startsWith('--') ? true : nextArg
}
}

Simple fix would be:

for (let i = 0; i < args.length; i++) {
  const arg = args[i]
  const nextArg = args[i + 1]
  if (arg.startsWith('--')) {
    options[arg.replace('--', '')] =
      !nextArg || nextArg.startsWith('--') ? true : nextArg
  } else if((arg === '-c' || arg === '--config') && (nextArg && !nextArg.startsWith('-'))) {
    options.configFile = nextArg
  }
}

A possibly cleaner solution

const options = args.reduce((options, current, index, args) => {
	if (!current.startsWith('-')) return options
	
	const next = args[index + 1]
	const currentIsConfigOption = current === '-c' || current === '--config'
	const nextIsOptionName = next && next.startsWith('--')

	if (currentIsConfigOption)
		if (!next || nextIsOptionName) return options
		else options.configFile = next
	else if(current.startsWith('--')) {
		const optionName = current.replace('--', '')
		options[optionName] = !next || nextIsOptionName ? true : next
	}

	return options
}, {});
@MichealPearce
Copy link
Author

The build command would also need some kind of solution I am now realizing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant