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-plugin-cp

v4.0.8

Published

Copy files after building bundles.

Downloads

17,526

Readme

vite-plugin-cp

npm package

Copy files after building bundles. Vite >= 3.1 打包之后复制文件

NPM version NPM Downloads

Installation

npm install vite-plugin-cp --save-dev

Options

export interface Target {
  /**
   * Path or glob of what to copy.
   *
   * 要复制的目录、文件或者 `globby` 匹配规则。
   */
  src: string | string[];

  /**
   * One or more destinations where to copy.
   *
   * 复制到目标目录。
   */
  dest: string;

  /**
   * Rename the file after copying.
   *
   * 复制后重命名文件。
   */
  rename?: string | ((name: string) => string);

  /**
   * Remove the directory structure of copied files, if `src` is a directory.
   *
   * 是否删除复制的文件目录结构,`src` 为目录时有效。
   */
  flatten?: boolean;

  /**
   * Options for globby. See more at https://github.com/sindresorhus/globby#options
   *
   * globby 的选项,设置 `src` 的匹配参数
   */
  globbyOptions?: GlobbyOptions;

  /**
   * Transform the file before copying.
   *
   * 复制前转换文件内容。
   */
  transform?: (buf: Buffer, matchedPath: string) => string | Buffer | Promise<string | Buffer>;
}

export interface Options {
  /**
   * Default `'closeBundle'`, vite hook the plugin should use.
   *
   * 默认 `'closeBundle'`,调用到指定钩子函数时开始复制。
   */
  hook?: string;

  /**
   * The value of enforce can be either `"pre"` or `"post"`, see more at https://vitejs.dev/guide/api-plugin.html#plugin-ordering.
   *
   * 强制执行顺序,`pre` 前,`post` 后,参考 https://cn.vitejs.dev/guide/api-plugin.html#plugin-ordering
   */
  enforce?: 'pre' | 'post';

  /**
   * Options for globby. See more at https://github.com/sindresorhus/globby#options
   *
   * globby 的选项,设置 `src` 的匹配参数
   */
  globbyOptions?: GlobbyOptions;

  /**
   * Default `process.cwd()`, The current working directory in which to search.
   *
   * 默认 `process.cwd()`,在该目录下搜索。
   */
  cwd?: string;

  /**
   * Array of targets to copy.
   *
   * 复制文件的规则配置。
   */
  targets: Target[];
}

Option | Type | Default | Description ------ | ---- | ------- | ----------- hook | string | 'closeBundle' | vite hook the plugin should use. 调用指定钩子函数时开始复制。 enforce | 'pre' \| 'post' | Optional | The value of enforce can be either "pre" or "post", see more at https://vitejs.dev/guide/api-plugin.html#plugin-ordering. 强制执行顺序,pre 前,post 后,参考 https://cn.vitejs.dev/guide/api-plugin.html#plugin-ordering globbyOptions | GlobbyOptions | Optional | Options for globby. See more at https://github.com/sindresorhus/globby#options. globby 的选项,设置 src 的匹配参数。 cwd | string | process.cwd() | The current working directory in which to search. 用于拼接 src 的路径。 targets | Target[] | Optional | Array of targets to copy. 复制文件的规则配置。

Target | Type | Default | Description ------ | ---- | ------- | ----------- src | string \| string[] | Required | Path or glob of what to copy. 要复制的目录、文件或者 globby 匹配规则。 dest | string | Optional | One or more destinations where to copy. 复制到目标目录。 rename | string \| ((name: string) => string) | Optional | Rename the file after copying. flatten | boolean | Optional | Remove the directory structure of copied files, if src is a directory. 是否删除复制的文件目录结构,src 为目录时有效。 globbyOptions | GlobbyOptions | Optional | Options for globby. See more at https://github.com/sindresorhus/globby#options. globby 的选项,设置 src 的匹配参数 transform | (buf: Buffer, matchedPath: string) => string \| Buffer \| Promise<string \| Buffer> | Optional | Transform the file before copying. 复制前转换文件内容。

Usage

import { defineConfig } from 'vite';
import cp from 'vite-plugin-cp';

export default defineConfig({
  plugins: [
    cp({
      targets: [
        // copy files of './node_modules/vite/dist' to 'dist/test'
        { src: './node_modules/vite/dist', dest: 'dist/test' },

        // copy files of './node_modules/vite/dist' to 'dist/test2' 
        // and keep the directory structure of copied files
        { src: './node_modules/vite/dist', dest: 'dist/test2', flatten: false },

        // copy './node_modules/vite/README.md' to 'dist'
        { src: './node_modules/vite/README.md', dest: 'dist' },

        // copy './node_modules/vite/**/*.ts' to 'dist/types'
        { src: './node_modules/vite/**/*.ts', dest: 'dist/types' }
      ]
    })
  ]
});

Examples