New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@col0ring/vite-plugin-copy

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@col0ring/vite-plugin-copy

A vite plugin for copying dirs or files after building.

latest
Source
npmnpm
Version
1.0.2
Version published
Weekly downloads
157
-32.33%
Maintainers
1
Weekly downloads
 
Created
Source

Vite-Plugin-Copy

A vite plugin for copying dirs or files after building.

Install

npm install @col0ring/vite-plugin-copy -D
# or
yarn add @col0ring/vite-plugin-copy -D

Usage

import { defineConfig } from 'vite'
import path from 'path'
import viteCopyPlugin from '@col0ring/vite-plugin-copy'

function resolve(relativePath: string) {
  return path.resolve(__dirname, relativePath)
}

export default defineConfig({
  plugins: [
    // ...
    viteCopyPlugin([
      {
        src: resolve('./dist/index.html'),
        target: resolve('./dist/index2.html')
      }
    ])
  ]
})

The src and target options can accept arrays:

import { defineConfig } from 'vite'
import path from 'path'
import viteCopyPlugin from '@col0ring/vite-plugin-copy'

function resolve(relativePath: string) {
  return path.resolve(__dirname, relativePath)
}

export default defineConfig({
  plugins: [
    // ...
    viteCopyPlugin([
      {
        src: resolve('./dist/index.html'),
        target: [resolve('./dist/index2.html'), resolve('./dist/index3.html')]
      }
    ])
  ]
})
import { defineConfig } from 'vite'
import path from 'path'
import viteCopyPlugin from '@col0ring/vite-plugin-copy'

function resolve(relativePath: string) {
  return path.resolve(__dirname, relativePath)
}

export default defineConfig({
  plugins: [
    // ...
    viteCopyPlugin([
      {
        src: [resolve('./dist/index.html'), resolve('./dist/assets')],
        target: [resolve('./dist/dist2'), resolve('./dist/dist3')]
      }
    ])
  ]
})

The disk path supports glob:

import { defineConfig } from 'vite'
import path from 'path'
import viteCopyPlugin from '@col0ring/vite-plugin-copy'

function resolve(relativePath: string) {
  return path.resolve(__dirname, relativePath)
}

export default defineConfig({
  plugins: [
    // ...
    viteCopyPlugin([
      {
        // move all files in the src directory to the target directory
        src: resolve('./dist/assets/**/*'),
        target: resolve('./dist/assets2')
      }
    ])
  ]
})

Usually, the plugin will automatically recognize whether the copy is a directory or a file, but you can still specify it manually:

import { defineConfig } from 'vite'
import path from 'path'
import viteCopyPlugin from '@col0ring/vite-plugin-copy'

function resolve(relativePath: string) {
  return path.resolve(__dirname, relativePath)
}

export default defineConfig({
  plugins: [
    // ...
    viteCopyPlugin([
      {
        // this is a file
        src: resolve('./dist/file'),
        target: {
          isDir: false,
          path: resolve('./dist/file2')
        }
      }
    ])
  ]
})

Delare

function vitePluginCopy(
  options: CopyOptions[],
  globOptions?: glob.IOptions
): Plugin

CopyOptions

src

  • Type: string | string[]

Resource file or directory.

target

  • Type: string | string[] | TargetObject | TargetObject[]

Target file or directory.

interface TargetObject {
  isDir?: boolean
  path: string
}

glob.IOptions

Custom glob configuration.

FAQs

Package last updated on 28 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts