1 | # rollup-plugin-copy
|
2 |
|
3 | [![Build Status](https://travis-ci.com/vladshcherbin/rollup-plugin-copy.svg?branch=master)](https://travis-ci.com/vladshcherbin/rollup-plugin-copy)
|
4 | [![Codecov](https://codecov.io/gh/vladshcherbin/rollup-plugin-copy/branch/master/graph/badge.svg)](https://codecov.io/gh/vladshcherbin/rollup-plugin-copy)
|
5 |
|
6 | Copy files and folders, with glob support.
|
7 |
|
8 | ## Installation
|
9 |
|
10 | ```bash
|
11 | # yarn
|
12 | yarn add rollup-plugin-copy -D
|
13 |
|
14 | # npm
|
15 | npm install rollup-plugin-copy -D
|
16 | ```
|
17 |
|
18 | ## Usage
|
19 |
|
20 | ```js
|
21 | // rollup.config.js
|
22 | import copy from 'rollup-plugin-copy'
|
23 |
|
24 | export default {
|
25 | input: 'src/index.js',
|
26 | output: {
|
27 | file: 'dist/app.js',
|
28 | format: 'cjs'
|
29 | },
|
30 | plugins: [
|
31 | copy({
|
32 | targets: [
|
33 | { src: 'src/index.html', dest: 'dist/public' },
|
34 | { src: ['assets/fonts/arial.woff', 'assets/fonts/arial.woff2'], dest: 'dist/public/fonts' },
|
35 | { src: 'assets/images/**/*', dest: 'dist/public/images' }
|
36 | ]
|
37 | })
|
38 | ]
|
39 | }
|
40 | ```
|
41 |
|
42 | ### Configuration
|
43 |
|
44 | There are some useful options:
|
45 |
|
46 | #### targets
|
47 |
|
48 | Type: `Array` | Default: `[]`
|
49 |
|
50 | Array of targets to copy. A target is an object with properties:
|
51 |
|
52 | - **src** (`string` `Array`): Path or glob of what to copy
|
53 | - **dest** (`string` `Array`): One or more destinations where to copy
|
54 | - **rename** (`string` `Function`): Change destination file or folder name
|
55 | - **transform** (`Function`): Modify file contents
|
56 |
|
57 | Each object should have **src** and **dest** properties, **rename** and **transform** are optional. [globby](https://github.com/sindresorhus/globby) is used inside, check it for [glob pattern](https://github.com/sindresorhus/globby#globbing-patterns) examples.
|
58 |
|
59 | ##### File
|
60 |
|
61 | ```js
|
62 | copy({
|
63 | targets: [{ src: 'src/index.html', dest: 'dist/public' }]
|
64 | })
|
65 | ```
|
66 |
|
67 | ##### Folder
|
68 |
|
69 | ```js
|
70 | copy({
|
71 | targets: [{ src: 'assets/images', dest: 'dist/public' }]
|
72 | })
|
73 | ```
|
74 |
|
75 | ##### Glob
|
76 |
|
77 | ```js
|
78 | copy({
|
79 | targets: [{ src: 'assets/*', dest: 'dist/public' }]
|
80 | })
|
81 | ```
|
82 |
|
83 | ##### Glob: multiple items
|
84 |
|
85 | ```js
|
86 | copy({
|
87 | targets: [{ src: ['src/index.html', 'src/styles.css', 'assets/images'], dest: 'dist/public' }]
|
88 | })
|
89 | ```
|
90 |
|
91 | ##### Glob: negated patterns
|
92 |
|
93 | ```js
|
94 | copy({
|
95 | targets: [{ src: ['assets/images/**/*', '!**/*.gif'], dest: 'dist/public/images' }]
|
96 | })
|
97 | ```
|
98 |
|
99 | ##### Multiple targets
|
100 |
|
101 | ```js
|
102 | copy({
|
103 | targets: [
|
104 | { src: 'src/index.html', dest: 'dist/public' },
|
105 | { src: 'assets/images/**/*', dest: 'dist/public/images' }
|
106 | ]
|
107 | })
|
108 | ```
|
109 |
|
110 | ##### Multiple destinations
|
111 |
|
112 | ```js
|
113 | copy({
|
114 | targets: [{ src: 'src/index.html', dest: ['dist/public', 'build/public'] }]
|
115 | })
|
116 | ```
|
117 |
|
118 | ##### Rename with a string
|
119 |
|
120 | ```js
|
121 | copy({
|
122 | targets: [{ src: 'src/app.html', dest: 'dist/public', rename: 'index.html' }]
|
123 | })
|
124 | ```
|
125 |
|
126 | ##### Rename with a function
|
127 |
|
128 | ```js
|
129 | copy({
|
130 | targets: [{
|
131 | src: 'assets/docs/*',
|
132 | dest: 'dist/public/docs',
|
133 | rename: (name, extension, fullPath) => `${name}-v1.${extension}`
|
134 | }]
|
135 | })
|
136 | ```
|
137 |
|
138 | ##### Transform file contents
|
139 |
|
140 | ```js
|
141 | copy({
|
142 | targets: [{
|
143 | src: 'src/index.html',
|
144 | dest: 'dist/public',
|
145 | transform: (contents, filename) => contents.toString().replace('__SCRIPT__', 'app.js')
|
146 | }]
|
147 | })
|
148 | ```
|
149 |
|
150 | #### verbose
|
151 |
|
152 | Type: `boolean` | Default: `false`
|
153 |
|
154 | Output copied items to console.
|
155 |
|
156 | ```js
|
157 | copy({
|
158 | targets: [{ src: 'assets/*', dest: 'dist/public' }],
|
159 | verbose: true
|
160 | })
|
161 | ```
|
162 |
|
163 | #### hook
|
164 |
|
165 | Type: `string` | Default: `buildEnd`
|
166 |
|
167 | [Rollup hook](https://rollupjs.org/guide/en/#hooks) the plugin should use. By default, plugin runs when rollup has finished bundling, before bundle is written to disk.
|
168 |
|
169 | ```js
|
170 | copy({
|
171 | targets: [{ src: 'assets/*', dest: 'dist/public' }],
|
172 | hook: 'writeBundle'
|
173 | })
|
174 | ```
|
175 |
|
176 | #### copyOnce
|
177 |
|
178 | Type: `boolean` | Default: `false`
|
179 |
|
180 | Copy items once. Useful in watch mode.
|
181 |
|
182 | ```js
|
183 | copy({
|
184 | targets: [{ src: 'assets/*', dest: 'dist/public' }],
|
185 | copyOnce: true
|
186 | })
|
187 |
|
188 | ```
|
189 | #### copySync
|
190 |
|
191 | Type: `boolean` | Default: `false`
|
192 |
|
193 | Copy items synchronous.
|
194 |
|
195 | ```js
|
196 | copy({
|
197 | targets: [{ src: 'assets/*', dest: 'dist/public' }],
|
198 | copySync: true
|
199 | })
|
200 | ```
|
201 |
|
202 | #### flatten
|
203 |
|
204 | Type: `boolean` | Default: `true`
|
205 |
|
206 | Remove the directory structure of copied files.
|
207 |
|
208 | ```js
|
209 | copy({
|
210 | targets: [{ src: 'assets/**/*', dest: 'dist/public' }],
|
211 | flatten: false
|
212 | })
|
213 | ```
|
214 |
|
215 | All other options are passed to packages, used inside:
|
216 | - [globby](https://github.com/sindresorhus/globby)
|
217 | - [fs-extra copy function](https://github.com/jprichardson/node-fs-extra/blob/7.0.0/docs/copy.md)
|
218 |
|
219 | ## Original Author
|
220 |
|
221 | [Cédric Meuter](https://github.com/meuter)
|
222 |
|
223 | ## License
|
224 |
|
225 | MIT
|