3.5.0 • Published 8 months ago

rollup-plugin-copy v3.5.0

Weekly downloads
182,432
License
MIT
Repository
github
Last release
8 months 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-olobsidian-reloaderoscar-callpackage-cli-servicenova-tasksnova-linksnovuinova-design-elementsnova-docsnova-drivenpm-tester-by-pugalarasannpm-tester-by-pugalmobile-agility-componentsminy-utilsmokshatestmobin-range-pickernhsuk-prototype-rigpeek-excelpds-demo-componentspharmasoft-core-vuenuxt-module-buildernuxt-module-kitpostman2apipostpimcore-vite-pluginmonorepo-buildermove-by-arrow-keyqiao-projectbeta-sp-uibetter-content-ui@deutsche-audio/crbn-player@archielite/vite-define-config@arc-ui/bundlezohary-test-component-libraryzoi-file-dropzp-eslint-init@catena-network/catena-ui-module@chainsafe/common-theme@cheryx2020/core@doctorwork/remax-cli@corva/dc-platform-shared@doraemon-ui/miniprogram.tools@citolab/tspciboshan-ui@cnc-ti/lib-cnc@cobrains/react-env@cloudie/drops@claimini/ui-componentsbraver-ui-react@codeunic/library-ui@codekin/deoxy-component-library@cruk/chakra-components@coinswap-libs/connbss-ui@cscart/tools@cubitrix/cubitrix-react-ui-module@darrenmothersele/builder@dannyfi/sdkcap-rollup-configcard-npmcesium-mwebb-lite-componentvue-flags@virc/create-virc-app@arters/rollup-config@beyonk/snowpack-rollup-pluginz-mining-base@brixtol/rollup-config@brc-chain/sdk@axdspub/axiom-mapsbattle-of-the-elements-fe-library@bygd/gd-sdk-air-dynamic
3.5.0

8 months ago

3.4.0

3 years ago

3.3.0

4 years ago

3.2.1

4 years ago

3.2.0

4 years ago

3.1.0

5 years ago

3.0.0

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago

0.3.0

5 years ago

0.2.3

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago