3.5.0 • Published 1 year ago

rollup-plugin-copy v3.5.0

Weekly downloads
182,432
License
MIT
Repository
github
Last release
1 year ago

rollup-plugin-copy

Build Status Codecov

Copy files and folders, with glob support.

Installation

# yarn
yarn add rollup-plugin-copy -D

# npm
npm install rollup-plugin-copy -D

Usage

// rollup.config.js
import copy from 'rollup-plugin-copy'

export default {
  input: 'src/index.js',
  output: {
    file: 'dist/app.js',
    format: 'cjs'
  },
  plugins: [
    copy({
      targets: [
        { src: 'src/index.html', dest: 'dist/public' },
        { src: ['assets/fonts/arial.woff', 'assets/fonts/arial.woff2'], dest: 'dist/public/fonts' },
        { src: 'assets/images/**/*', dest: 'dist/public/images' }
      ]
    })
  ]
}

Configuration

There are some useful options:

targets

Type: Array | Default: []

Array of targets to copy. A target is an object with properties:

  • src (string Array): Path or glob of what to copy
  • dest (string Array): One or more destinations where to copy
  • rename (string Function): Change destination file or folder name
  • transform (Function): Modify file contents

Each object should have src and dest properties, rename and transform are optional. globby is used inside, check it for glob pattern examples.

File
copy({
  targets: [{ src: 'src/index.html', dest: 'dist/public' }]
})
Folder
copy({
  targets: [{ src: 'assets/images', dest: 'dist/public' }]
})
Glob
copy({
  targets: [{ src: 'assets/*', dest: 'dist/public' }]
})
Glob: multiple items
copy({
  targets: [{ src: ['src/index.html', 'src/styles.css', 'assets/images'], dest: 'dist/public' }]
})
Glob: negated patterns
copy({
  targets: [{ src: ['assets/images/**/*', '!**/*.gif'], dest: 'dist/public/images' }]
})
Multiple targets
copy({
  targets: [
    { src: 'src/index.html', dest: 'dist/public' },
    { src: 'assets/images/**/*', dest: 'dist/public/images' }
  ]
})
Multiple destinations
copy({
  targets: [{ src: 'src/index.html', dest: ['dist/public', 'build/public'] }]
})
Rename with a string
copy({
  targets: [{ src: 'src/app.html', dest: 'dist/public', rename: 'index.html' }]
})
Rename with a function
copy({
  targets: [{
    src: 'assets/docs/*',
    dest: 'dist/public/docs',
    rename: (name, extension, fullPath) => `${name}-v1.${extension}`
  }]
})
Transform file contents
copy({
  targets: [{
    src: 'src/index.html',
    dest: 'dist/public',
    transform: (contents, filename) => contents.toString().replace('__SCRIPT__', 'app.js')
  }]
})

verbose

Type: boolean | Default: false

Output copied items to console.

copy({
  targets: [{ src: 'assets/*', dest: 'dist/public' }],
  verbose: true
})

hook

Type: string | Default: buildEnd

Rollup hook the plugin should use. By default, plugin runs when rollup has finished bundling, before bundle is written to disk.

copy({
  targets: [{ src: 'assets/*', dest: 'dist/public' }],
  hook: 'writeBundle'
})

copyOnce

Type: boolean | Default: false

Copy items once. Useful in watch mode.

copy({
  targets: [{ src: 'assets/*', dest: 'dist/public' }],
  copyOnce: true
})

copySync

Type: boolean | Default: false

Copy items synchronous.

copy({
  targets: [{ src: 'assets/*', dest: 'dist/public' }],
  copySync: true
})

flatten

Type: boolean | Default: true

Remove the directory structure of copied files.

copy({
  targets: [{ src: 'assets/**/*', dest: 'dist/public' }],
  flatten: false
})

All other options are passed to packages, used inside:

Original Author

Cédric Meuter

License

MIT

cesium-plugin-vitecesium_yaoml_plugin_vitemf_nslogin@packmate/ui@bkinnamon/blademylib2-test-imgreact-mxgraph-editorbriolink-ui-kittq-muisbw-components-test@rakuten-rampage/rampagetaro-uilib@inbegroad-tools/admin@inbegroad-tools/cloneshapeshift-common@infinitebrahmanuniverse/nolb-rollup-plugin-c@samsquatch/service-titan-componentshdlocalhd-sfc-clidgtoolsprototypable-components@fqran/infinite-passrccalc-utilswitotireclound-pattern-librarythinktor-ui@everything-registry/sub-chunk-2680zhenyu-componentszhenyu-z-componentspoc-map-olnpm-tester-by-pugalarasandoeapi@cnc-ti/lib-cnctalentorg-profile-editortaro-sealtcsptcsp-test-vdtaro-eazytect-ui-compoanytest-custom-librarytest-ignore-5ctest-dummy-vivasoft-component-librarywidget-demo-chatwidget-upchatwinkey-init-project-seed-npmvue-mock-transitionwebb-lite-componentwebsprite.jswemeta-analytics-decentralandwwwqqqeeex-pro-componentswft-vue3-cup-uiwi9-sp-uixg-pdf-renderers2clientprotocolshaka-player-reactshaka-react-video-playershaka-react-video-player-xsheninthjr-cardshoelace-web-componentsscantscreenshottabrete-clirebel-ui-kitremax-clireact-widget-comroles_accessroll-scisunny_zee_uistoriesxxxixxxstorybook_dineshsdk-for-leaningsecureid-reactrolluptestqqqrollup-vue-tong-liangtest-public-topbar-idtrustedsvelte-prismjsswift-testtext-similarity-scorerthrigevizabi-tool-bundlervoluptatemnihilvnext-demovnmapvivasoft-component-libraryvite-hsbc-clivendor-generatorvue-flagstotology-componentskiuda-carbon-librarycym-test@rockrms/obsidian-build-toolsvoyage-optimization-mapnpm-tester-by-pugalpeek-exceltest-components6obsidian-reloadervfd-widgetvfd-widget-test@arters/rollup-config
3.5.0

1 year ago

3.4.0

4 years ago

3.3.0

5 years ago

3.2.1

5 years ago

3.2.0

5 years ago

3.1.0

5 years ago

3.0.0

5 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.3.0

6 years ago

0.2.3

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.5

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago