Skip to content

Commit 9ff593e

Browse files
committed
Update readme
1 parent 38af8ec commit 9ff593e

File tree

1 file changed

+69
-42
lines changed

1 file changed

+69
-42
lines changed

readme.md

+69-42
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,16 @@
33
[![Build Status](https://travis-ci.org/vladshcherbin/rollup-plugin-copy.svg?branch=master)](https://travis-ci.org/vladshcherbin/rollup-plugin-copy)
44
[![Codecov](https://codecov.io/gh/vladshcherbin/rollup-plugin-copy/branch/master/graph/badge.svg)](https://codecov.io/gh/vladshcherbin/rollup-plugin-copy)
55

6-
Copy files and folders using Rollup.
7-
8-
## About
9-
10-
This plugin is useful when you want to copy some files or folders before bundling.
6+
Copy files and folders, with glob support.
117

128
## Installation
139

1410
```bash
11+
# yarn
1512
yarn add rollup-plugin-copy -D
1613

17-
# or
18-
19-
npm install rollup-plugin-copy --save-dev
14+
# npm
15+
npm install rollup-plugin-copy -D
2016
```
2117

2218
## Usage
@@ -34,10 +30,9 @@ export default {
3430
plugins: [
3531
copy({
3632
targets: [
37-
'src/migrations',
38-
'src/index.html'
39-
],
40-
outputFolder: 'dist'
33+
{ src: 'src/index.html', dest: 'dist/public' },
34+
{ src: 'assets/images/**/*', dest: 'dist/public/images' }
35+
]
4136
})
4237
]
4338
}
@@ -49,78 +44,110 @@ There are some useful options:
4944

5045
#### targets
5146

52-
An array or an object with paths of files and folders to be copied. Default is `[]`.
47+
Type: `Array` | Default: `[]`
48+
49+
Array of targets to copy. A target is an object with properties:
50+
51+
- **src** (`string` `Array`): Path or glob of what to copy
52+
- **dest** (`string` `Array`): One or more destinations where to copy
53+
- **rename** (`string` `Function`): Change destination file or folder name
54+
55+
Each object should have **src** and **dest** properties, **rename** is optional.
56+
57+
##### File
5358

5459
```js
5560
copy({
56-
targets: ['src/assets', 'src/index.html'],
57-
outputFolder: 'dist'
61+
targets: [{ src: 'src/index.html', dest: 'dist/public' }]
5862
})
63+
```
5964

65+
##### Folder
66+
67+
```js
6068
copy({
61-
targets: {
62-
'src/assets': 'dist/public/assets',
63-
'src/index.html': 'dist/public/index.html',
64-
'src/favicon.ico': ['dist/favicon.ico', 'build/favicon.ico'],
65-
'src/images': ['dist/images', 'build/images']
66-
}
69+
targets: [{ src: 'assets/images', dest: 'dist/public' }]
6770
})
6871
```
6972

70-
> Note: if an array, *outputFolder* is required to be set
73+
##### Glob
7174

72-
> Note: if an object, multiple destinations can be set using array syntax
75+
```js
76+
copy({
77+
targets: [{ src: ['assets/images/**/*', '!**/*.gif'], dest: 'dist/public/images' }]
78+
})
79+
```
7380

74-
#### outputFolder
81+
##### Multiple destinations
7582

76-
Folder where files and folders will be copied. Required to be set when *targets* is an array.
83+
```js
84+
copy({
85+
targets: [{ src: 'src/index.html', dest: ['dist/public', 'build/public'] }]
86+
})
87+
```
88+
89+
##### Rename with a string
7790

7891
```js
7992
copy({
80-
targets: ['src/assets', 'src/index.html'],
81-
outputFolder: 'dist/public'
93+
targets: [{ src: 'src/app.html', dest: 'dist/public', rename: 'index.html' }]
8294
})
8395
```
8496

85-
> Note: only used when *targets* is an array
97+
##### Rename with a function
98+
99+
```js
100+
copy({
101+
targets: [{
102+
src: 'assets/docs/*',
103+
dest: 'dist/public/docs',
104+
rename: (name, extension) => `${name}-v1.${extension}`
105+
}]
106+
})
107+
```
86108

87109
#### verbose
88110

89-
Output copied files and folders to console. Default is `false`.
111+
Type: `boolean` | Default: `false`
112+
113+
Output copied items to console.
90114

91115
```js
92116
copy({
93-
targets: ['src/assets', 'src/index.html'],
94-
outputFolder: 'dist',
117+
targets: [{ src: 'assets/*', dest: 'dist/public' }],
95118
verbose: true
96119
})
97120
```
98121

99-
#### warnOnNonExist
122+
#### hook
100123

101-
Warn if target file or folder doesn't exist. Default is `false`.
124+
Type: `string` | Default: `buildEnd`
125+
126+
Rollup hook the plugin should use.
102127

103128
```js
104129
copy({
105-
targets: ['src/assets', 'src/index.html'],
106-
outputFolder: 'dist',
107-
warnOnNonExist: true
130+
targets: [{ src: 'assets/*', dest: 'dist/public' }],
131+
hook: 'buildStart'
108132
})
109133
```
110134

111-
#### hook
135+
#### copyOnce
136+
137+
Type: `boolean` | Default: `false`
112138

113-
Set which rollup hook the plugin should use. Default is `buildEnd`.
139+
Copy items once. Useful in watch mode.
114140

115141
```js
116142
copy({
117-
targets: ['src/assets', 'src/index.html'],
118-
outputFolder: 'dist',
119-
hook: 'generateBundle'
143+
targets: [{ src: 'assets/*', dest: 'dist/public' }],
144+
copyOnce: true
120145
})
121146
```
122147

123-
All other options are passed directly to [fs-extra copy function](https://github.com/jprichardson/node-fs-extra/blob/7.0.0/docs/copy.md), which is used inside.
148+
All other options are passed to packages, used inside:
149+
- [globby](https://github.com/sindresorhus/globby)
150+
- [fs-extra copy function](https://github.com/jprichardson/node-fs-extra/blob/7.0.0/docs/copy.md)
124151

125152
## Original Author
126153

0 commit comments

Comments
 (0)