Explore core concepts of Vite project setup and configuration with this medium-level quiz. Assess your understanding of initialization steps, configuration file details, environment variables, plugin integration, and basic build settings for fast modern front-end development.
Which command should you use to initialize a new Vite project using a template, such as vanilla or vue?
Explanation: The correct command to initialize a new Vite project with a specific template is 'npm create vite@latest my-app -- --template vanilla'. This syntax correctly uses the modern way to scaffold projects with template selection. 'vite install my-app --template react' and 'vite new my-app --type vanilla' are not valid commands and will result in errors. 'npx init-vite my-app template vanilla' is a plausible typo but does not correspond to the standard initialization process.
After creating a new Vite project, which configuration file will you typically edit to adjust basic settings like root directory or aliasing?
Explanation: The correct configuration file for editing setup options such as the root directory or import aliasing is 'vite.config.js'. This file is automatically detected by Vite on project startup. 'vitefile.js' and 'vite-settings.js' are not standard configuration filenames, and 'vite.config.json' is an incorrect format, as Vite expects the configuration as a JavaScript (or TypeScript) module.
When defining environment variables in a .env file for use in Vite's client-side code, what prefix must these variable names start with?
Explanation: Environment variables intended to be exposed in Vite’s client-side code must begin with 'VITE_'. Only variables with this prefix are included in the final build by design for security. Using 'ENV_', 'PUBLIC_', or 'CLIENT_' as prefixes will not make variables accessible in the client, so these distractors are incorrect.
To add a plugin, such as for processing custom files, to your Vite project, where should you declare it for correct integration?
Explanation: Plugins are declared in the 'plugins' array of the vite.config.js file for proper recognition and application during the project lifecycle. The package-lock.json is reserved for dependency management and the main.js entry file is for application logic, not configuration. There is no recognized 'plugins.config.json' for this purpose, making those options unsuitable.
If you want to change the directory where Vite outputs built production files, which configuration property should you modify?
Explanation: The correct property to change the output location for bundled files is 'build.outDir' within the configuration file. 'output.folder', 'distDirectory', and 'prod.output' are common-sounding but incorrect properties that will not be recognized by the build system, so modifying them has no effect on output path.