There are two ways to define tasks in Vite Task:
scriptsinpackage.json: Any script you define there can be run withvite run <script-name>, just likenpm run <script-name>.vite-task.json: You can also define tasks in a dedicatedvite-task.jsonfile.
The vite-task.json file lets you define tasks with more options than package.json scripts. It should be placed in the root of any package alongside package.json to define tasks for that package.
Here is an example of a vite-task.json file:
Configurable fields for each task:
command(string): The command to execute for the task.cwd(string, optional): The working directory to run the command in. Defaults to the directory containing thevite-task.jsonfile.dependsOn(array of strings, optional): A list of other tasks that this task depends on. See Task Orchestration for details.cache,envs,passthroughEnvs,inputs,outputs: see Configuring Cache for details.
If you want to keep your existing package.json scripts but also need custom configurations for them, you can define a task with the same name in vite-task.json. Vite Task will use the configuration from vite-task.json and the command from package.json.
For example, the following combination of package.json and vite-task.json:
// package.json
{
"scripts": {
"build": "webpack",
}
}
// vite-task.json
{
"tasks": {
"build": {
"envs": ["NODE_ENV"]
}
}
}is equivalent to:
// vite-task.json
{
"tasks": {
"build": {
"command": "webpack",
"envs": ["NODE_ENV"]
}
}
}If a script in
package.jsonand acommandinvite-task.jsonhave the same name, Vite Task will report the conflict and abort.
You can provide default configurations by defining defaults in vite-task.json at the root of the workspace. Each configuration defined in defaults will be applied to all tasks in the workspace with the same name, unless a task explicitly overrides it.
// vite-task.json
{
"defaults": {
"build": {
// Disable caching for all tasks named "build"
"cache": false
}
}
}The
defaultsfield is only allowed in the rootvite-task.jsonfile. Vite Task will report an error and abort if it finds one elsewhere.
{ "tasks": { "build": { "command": "webpack", "envs": ["NODE_ENV"] }, "test": { "command": "vite lint", "cwd": "./src" } } }