npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vite-run

v1.7.2

Published

Vite multi-configuration monorepo mode operation support (Vite monorepo模式多配置运行支持)

Downloads

4,118

Readme

中文 | English

vite 多配置执行支持, 配置共享,像搭积木一样自由组合配置, 颗粒度精确到单字段配置。 它可以完全替代vite.config,您无需在每个包中都创建一个vite.config配置 该工具在pnpm 多包模式下开发

install

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

Terminal commands

主命令 vite-run

| 子命令 | 参数 | 解释 | |----------|--------------------------|----------------------------------------------------| | | <配置名称> <一个或者多个包名...> | 运行一个或者多个包, 例如 vite-run build appName1 appName2 ... | | | -y | 不跳出交互页面直接运行 | | init | | 自动生成 viterun.config 文件 | | init | --cover | 强制覆盖本地 viterun.config 文件 | | init | --docs | 生成带文档解释的 viterun.config 文件 |

示例:

  • 执行全部包含dev的配置,不指定app名称则默认找到所有app中包含dev的配置并执行
     vite-run dev
     vite-run build
  • 为 app 和 app2 执行dev配置, app名称没有限制个数
     vite-run dev app1 app2

Simple Demonstration

下方只是简单演示示例,并非完整配置, 完整配置请见viterun.config.ts

dev dev

build build

manual-selection-app manual-selection

viterun.config [.js | .ts]

viterun.config是在项目根目录下创建的配置文件,类似vite.config, 后缀可以是js或者ts

import { defineViteRunConfig } from "vite-run";
export default defineViteRunConfig({
  // baseConfig:{},
  // packages:[],
  // target:{},
  // other vite config block map
})

baseConfig

  • desc 用于共享的vite配置,所有的配置块都会和其合并作为最终配置信息

  • type Function | object

    export default defineViteRunConfig({
       baseConfig:(options)=>{  // 使用函数形式,options包含子包信息,可以动态生成配置
          return {
            resolve: {
              extensions: [".ts",".js",'.vue'],
              alias: {
                "@": resolve(options.packagePath, 'src'),
             }
            },
            plugins: [
             // vue()
            ]
          }
       }
       // baseConfig:{}  直接使用对象形式
    })

packages

  • desc 要进行管理的子包列表,支持glob与文件路径,glob匹配只支持末尾带*号

  • struct Array<string>

    export default defineViteRunConfig({
       packages: [
         'packages/*',
         'examples/vue3',
         './'     //  支持操作主包
       ]
    })

targets [ 配置块只能在这里使用, 配置块说明请看下方术语解释 ]

  • desc 定义配置名和其要运行的[配置块]或者[配置块组]

  • struct { appName: { scriptName :[ configName | Array<configName> ] }}

    比如下方web-app中的 build 列表中存在两组配置: umd 是一个配置块,直接和baseConfig合并成最终配置。 ['es','production']是一个配置块组, 会先将该组合并(配置重叠会以后面配置为主)成同一个配置之后, 再和baseConfig合并成最终配置。

        export default defineViteRunConfig({
          targets: {
            'lib-app':{
               dev: ['watch']
            },
            'web-app': {
               build: [
                 ['es','production'],  // 配置块组
                 ['umd']
               ],
               dev:[
                 ['10000']
               ]
            },
          },
        })
        ```
    

Other vite config block map

vite.configviterun.config针对配置vite配置是存在区别的 : viterun在原本vite的 配置上使用一个对象包裹起来,为每个vite配置块命名, 原本的vite配置则作为该键名的值

// vite 配置结构
export default defineViteRunConfig({
  build: {
    lib: {
       formats: ['es']
    },
    watch: {},
  },
  server: {
    port: 10000
  },
})
//--------------------------------------------
// viterun 配置结构
export default defineViteRunConfig({
  build: {
    // es:{     // 支持使用对象形式
    //   lib:{
    //      formats: ['es']
    //    }
    // },
    es:(options)=> {  // 支持函数形式返回,options包含子包信息
      return {
        lib: {
          formats: ['es']
        }
      }
    },
    watch: {
      watch:{}
    },
  },
  server: {
    10000: {
      port: 10000
    },
  },
})

viteRunLogPlugin

您如果需要管控和优化控制台输出信息,viterun内置了一个viteRunLogPlugin插件 该插件能控制vite默认日志输出 和 viterun工具的日志输出 您可以直接导入使用,配置和使用信息请自行点击编辑器链接到d.ts文件中查看

import { viteRunLogPlugin } from 'vite-run'

interceptStdoutWriteLog

如果您有拦截其他日志输出的需求,你可以使用interceptStdoutWriteLog函数, 该插件能控制和拦截所有输出到控制台的字符串流信息

import { interceptStdoutWriteLog } from 'vite-run'
interceptStdoutWriteLog((log)=>{
    console.warn(log)  // 如果console.log用不了,请使用console.warn
    // 返回 true 表示输出该日志,返回false表示不输出该日志,
    // 如果想修改日志,直接返回false,然后console.warn手动输出就行
    return true
})

术语解释

  1. 配置块: 比如下面配置中 es 就是配置块名称, es对应的值便是原本vite配置的build对象, 配置块也可以叫做vite配置块,指的就是vite配置中的一小部分,并为其取名方便后面自由组合配置
    export default defineViteRunConfig({
      build: {
        es: {
          lib: {
            formats: ['umd']
          },
        }
      }
    })
  2. 配置名称: 比如下方的dev就是配置名称,里面包含多个vite配置块, dev数组里面每个数组成员(配置块组)最终都会生成一个独立的vite配置
    export default defineViteRunConfig({
       targets: {
         'lib-app':{
            dev: [
              ['watch','es'],
            ]
         },
       }
     })

许可证

MIT 许可证.