Home

Awesome

<h1 align="center">vite-run</h1> <br/> <p align="center"> <a href="https://npmjs.com/package/vite-run"> <img src="https://img.shields.io/npm/v/vite-run.svg" alt="npm package"> </a> <a href="https://img.shields.io/npm/l/vite-run"> <img src="https://img.shields.io/npm/l/vite-run?" alt="license"/> </a> </p> <br/>

English | 中文

Multiple configuration execution support for vite, configuration sharing, and free combination of configurations like building blocks, Granularity is accurate to single field configuration It can completely replace vite.config, you don't need to create a vite.config configuration in each package This tool is developed in pnpm multi package mode

install

    yarn add vite -D
    yarn add vite-run -D
    pnpm add vite -D
    pnpm add vite-run -D

Terminal commands

Main command vite-run

Subcommandsparameterexplain
<Configuration Name> <One or more package names ...>Run one or more packages, example: vite-run build appName1 appName2 ...
-yRun directly without jumping out of the interactive page
initAutomatically generate viterun.config file
init--coverForce overwrite of local viterun.config file
init--docsGenerate a viterun.config file with document explanation

example:

Simple Demonstration

The following is just a simple demonstration, not a complete configuration. Please refer to the complete configuration for more information viterun.config.ts

dev dev

build build

manual-selection-app manual-selection

viterun.config [.js | .ts]

Viterun.config is a configuration file created in the project root directory, similar to vite.config , The suffix can be js or ts

import {defineViteRunConfig} from "vite-run";

export default defineViteRunConfig({
  // baseConfig:{},
  // packages:[],
  // target:{},
  // other vite config block map
})

baseConfig

desc For shared vite configuration, all configuration blocks will be merged with it as the final configuration information

packages

desc The list of sub packages to be managed supports global and file paths, and global matching only supports ending with an * sign

targets

The configuration block can only be used here. Please refer to the terminology explanation below for the description of the configuration block

Other vite config block map

There are differences between vite.config and viterun.config for configuring vite configurations: vterunwraps an object around the original vite configuration and names each vite configuration block. The original vite configuration serves as the value of the key name

// vite configuration structure
export default defineViteRunConfig({
  build: {
    lib: {
      formats: ['es']
    },
    watch: {},
  },
  server: {
    port: 10000
  },
})
//--------------------------------------------
// viterun configuration structure
export default defineViteRunConfig({
  build: {
    // es:{     // Supports the use of object forms
    //   lib:{
    //      formats: ['es']
    //    }
    // },
    es: (options) => {  // Supports functional returns, with options containing subpackage information
      return {
        lib: {
          formats: ['es']
        }
      }
    },
    watch: {
      watch: {}
    },
  },
  server: {
    10000: {
      port: 10000
    },
  },
})


viteRunLogPlugin

If you need to control and optimize console output information, viterun has a built-in viteRunLogPlugin plugin This plugin can control the default log output of vite and the log output of viterun tool You can directly import and use it. Please click on the editor link to view the configuration and usage information in the d. ts file yourself

import {viteRunLogPlugin} from 'vite-run'

interceptStdoutWriteLog

If you have a need to intercept other log outputs, you can use the interceptStdoutWriteLog function, This plugin can control and intercept all character stream information output to the console

import {interceptStdoutWriteLog} from 'vite-run'

interceptStdoutWriteLog((log) => {
  console.warn(log)  // If console. log cannot be used, please use console. warn
  //Returning true indicates that the log is output, while returning false indicates that the log is not output,
  //If you want to modify the log, simply return false and manually output it from console. warn
  return true
})

Terminology

  1. configuration block: For example, in the following configuration, es is the name of the configuration block, The value corresponding to es is the build object originally configured by vite, Configuration blocks, also known as vite configuration blocks, refer to a small part of the vite configuration and are named for easy combination and configuration in the future

    export default defineViteRunConfig({
      build: {
        es: {
          lib: {
            formats: ['umd']
          },
        }
      }
    })
    
  2. configuration name: For example, dev below is the configuration name, which contains multiple vite configuration blocks, Each array member (configuration block group) in the dev array will ultimately generate an independent vite configuration

    export default defineViteRunConfig({
       targets: {
         'lib-app':{
            dev: [
              ['watch',  'es'],
            ]
         },
       }
     })
    

License

MIT License.