Skip to content

xiankq/unplugin-copy

Repository files navigation

unplugin-copy

Replace variables in code with other values or expressions. Supports Vite, Rollup, Webpack, Rspack and more.

NPM version

NOTE

The original intention of this plugin is to provide compatibility for lower-level plugins. You should give priority to using the copy that comes with the build tool.

Features

  • Support Vite, Webpack, Vue CLI, Rollup, esbuild and more, powered by unplugin.
  • In the Vite development environment, path mapping is used instead of real copying.

Install

npm i unplugin-copy -D

pnpm i unplugin-copy -D

yarn i unplugin-copy -D

Install

Vite
// vite.config.ts
import unpluginCopy from 'unplugin-copy/vite'

export default defineConfig({
  plugins: [
    unpluginCopy({
      targets: [
        // http://localhost:5173/vue/index.js => node_modules/vue/index.js
        {
          src: 'node_modules/vue/**',
          dest: 'vue',
        },
      ],
    }),
  ],
})


Rollup
// rollup.config.js
import unpluginCopy from 'unplugin-copy/rollup'

export default {
  plugins: [
    unpluginCopy({
      targets: [
        // http://localhost:5173/vue/index.js => node_modules/vue/index.js
        {
          src: 'node_modules/vue/**',
          dest: 'vue',
        },
      ],
    }),
  ],
}


Webpack
// webpack.config.js
module.exports = {
  /* ... */
  plugins: [
    unpluginCopy({
      targets: [
        // http://localhost:5173/vue/index.js => node_modules/vue/index.js
        {
          src: 'node_modules/vue/**',
          dest: 'vue',
        },
      ],
    }),
  ]
}


Nuxt
// nuxt.config.js
export default {
  buildModules: [
    ['unplugin-copy/nuxt', {
      targets: [
        // http://localhost:5173/vue/index.js => node_modules/vue/index.js
        {
          src: 'node_modules/vue/**',
          dest: 'vue',
        },
      ],
    }],
  ],
}

This module works for both Nuxt 2 and Nuxt Vite


Vue CLI
// vue.config.js
module.exports = {
  configureWebpack: {
    plugins: [
      require('unplugin-copy/webpack')({
        targets: [
        // http://localhost:5173/vue/index.js => node_modules/vue/index.js
          {
            src: 'node_modules/vue/**',
            dest: 'vue',
          },
        ],
      }),
    ],
  },
}


esbuild
// esbuild.config.js
import { build } from 'esbuild'
import unpluginCopy from 'unplugin-copy/esbuild'

build({
  plugins: [
    unpluginCopy({
      targets: [
        // http://localhost:5173/vue/index.js => node_modules/vue/index.js
        {
          src: 'node_modules/vue/**',
          dest: 'vue',
        },
      ],
    }),
  ],
})


The code idea comes from vite-plugin-static-copy.

About

Replace variables in code with other values or expressions. Supports Vite, Rollup, Webpack, Rspack and more.

Resources

License

Stars

2 stars

Watchers

1 watching

Forks

Sponsor this project

Packages

 
 
 

Contributors