1.0.1 • Published 9 months ago

unplugin-copy v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

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.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.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.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.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.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.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.

1.0.1

9 months ago

1.0.0

9 months ago

0.1.8

9 months ago

0.1.9

9 months ago

0.1.4

11 months ago

0.1.3

11 months ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago