• Stars
    star
    275
  • Rank 149,796 (Top 3 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 3 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

rollup-plugin-copy with dev server support.

vite-plugin-static-copy

npm version CI MIT License

rollup-plugin-copy for Vite with dev server support.

Note Before you use this plugin, consider using public directory or import in JavaScript. In most cases, these will work.

Install

npm i -D vite-plugin-static-copy # yarn add -D vite-plugin-static-copy

Usage

Add viteStaticCopy plugin to vite.config.js / vite.config.ts.

// vite.config.js / vite.config.ts
import { viteStaticCopy } from 'vite-plugin-static-copy'

export default {
  plugins: [
    viteStaticCopy({
      targets: [
        {
          src: 'bin/example.wasm',
          dest: 'wasm-files'
        }
      ]
    })
  ]
}

For example, if you use the config above, you will be able to fetch bin/example.wasm with fetch('/wasm-files/example.wasm'). So the file will be copied to dist/wasm-files/example.wasm.

Warning

If you are using Windows, make sure to use normalizePath after doing path.resolve or else. \ is a escape charactor in fast-glob and you should use /.

import { normalizePath } from 'vite'
import path from 'node:path'

normalizePath(path.resolve(__dirname, './foo')) // C:/project/foo

// instead of
path.resolve(__dirname, './foo') // C:\project\foo

See fast-glob documentation about this for more details.

Options

See options.ts.

Differences with rollup-plugin-copy

  • Faster dev server start-up than using rollup-plugin-copy on buildStart hook.
    • Files are not copied and served directly from the server during dev to reduce start-up time.
  • dest is relative to build.outDir.
    • If you are going to copy files outside build.outDir, you could use rollup-plugin-copy instead. Because that does not require dev server support.
  • fast-glob is used instead of globby.
    • Because fast-glob is used inside vite.
  • transform could return null as a way to tell the plugin not to copy the file, this is similar to the CopyWebpackPlugin#filter option, but it expects transform to return the original content in case you want it to be copied.
  • transform can optionally be an object, with a handler property (with the same signature of the rollup-plugin-copy transform option) and an encoding property (BufferEncoding | 'buffer') that will be used to read the file content so that the handler's content argument will reflect the correct encoding (could be Buffer);
  • structured: true preserves the directory structure. This is similar to flatten: false in rollup-plugin-copy, but it covers more edge cases.

More Repositories

1

vite-setup-catalogue

This repository contains several example of Vite setups.
TypeScript
193
star
2

vitest-github-actions-reporter

Vitest reporter to create annotations when running tests in GitHub Actions
TypeScript
48
star
3

micro-vite

create a minimal Vite like tool in 350 lines
TypeScript
44
star
4

web-noise-suppressor

Noise suppressor nodes for Web Audio API.
TypeScript
35
star
5

vitepress-plugins

Some vitepress plugins.
TypeScript
35
star
6

typescript-plugin-toml

A typescript language service plugin providing support for toml files.
TypeScript
15
star
7

vite-envs

TypeScript
12
star
8

DTLN-web

Use DTLN real time speech denoising model(https://github.com/breizhn/DTLN) in web.
TypeScript
10
star
9

speex-preprocess-wasm

WebAssembly build of SpeexDSP preprocess
TypeScript
10
star
10

sapphi-red

About me.
10
star
11

vue-convert-to-script-setup-from-composition-api

TypeScript
8
star
12

vue-routider

[archived: use unplugin-vue-router instead] Make vue-router type safe.
TypeScript
8
star
13

vite-plugin-toml

A plugin for rollup/vite to import a toml file.
TypeScript
7
star
14

portfolio

about me
JavaScript
6
star
15

vite-plugin-chemiscript

[abandoned] https://vue-macros.sxzz.moe/ maybe interesting for you
TypeScript
6
star
16

swagger-ui-plugin-enum-names

A plugin for Swagger UI to show `x-enum-varnames` / `x-enumNames` and `x-enum-descriptions`.
JavaScript
5
star
17

hubot-traq

Hubot adapter for traQ
JavaScript
4
star
18

artichokie

Mutual callable worker thread pool with fallback. Based on okie.
TypeScript
4
star
19

midec

Pure go multi-image detector. cf. Animated GIF, APNG, Animated WebP, Animated HEIF/AVIF.
Go
3
star
20

web-speed-hackathon-2021-mini

JavaScript
3
star
21

vite-boilerplate-plus

Vite boilerplate with Vue Router & Vuex.
Vue
2
star
22

ts-transformer-for-of

A TypeScript custom transformer to transform `for-of` and array methods to a normal `for` loop.
TypeScript
2
star
23

ex3asm-language

JavaScript
1
star
24

grook

[DEAD] a package for jpeg2000 conversion using grok. Abandoned because Safari now supports webp.
C++
1
star
25

extract-background

extracts background image
TypeScript
1
star
26

parallel-js-plugin-experiment

JavaScript
1
star
27

noise-reduction-slide-ja

CSS
1
star
28

es-module-lexer-repl

TypeScript
1
star
29

possibleerrors

Points out a code which is likely a logic error. (golang)
Go
1
star
30

node-midec

Multi-image detector (Wasm). cf. Animated GIF, APNG, Animated WebP, Animated HEIF/AVIF.
Go
1
star