3
3
[ ![ Build Status] ( https://travis-ci.org/vladshcherbin/rollup-plugin-copy.svg?branch=master )] ( https://travis-ci.org/vladshcherbin/rollup-plugin-copy )
4
4
[ ![ Codecov] ( https://codecov.io/gh/vladshcherbin/rollup-plugin-copy/branch/master/graph/badge.svg )] ( https://codecov.io/gh/vladshcherbin/rollup-plugin-copy )
5
5
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.
11
7
12
8
## Installation
13
9
14
10
``` bash
11
+ # yarn
15
12
yarn add rollup-plugin-copy -D
16
13
17
- # or
18
-
19
- npm install rollup-plugin-copy --save-dev
14
+ # npm
15
+ npm install rollup-plugin-copy -D
20
16
```
21
17
22
18
## Usage
@@ -34,10 +30,9 @@ export default {
34
30
plugins: [
35
31
copy ({
36
32
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
+ ]
41
36
})
42
37
]
43
38
}
@@ -49,78 +44,110 @@ There are some useful options:
49
44
50
45
#### targets
51
46
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
53
58
54
59
``` js
55
60
copy ({
56
- targets: [' src/assets' , ' src/index.html' ],
57
- outputFolder: ' dist'
61
+ targets: [{ src: ' src/index.html' , dest: ' dist/public' }]
58
62
})
63
+ ```
59
64
65
+ ##### Folder
66
+
67
+ ``` js
60
68
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' }]
67
70
})
68
71
```
69
72
70
- > Note: if an array, * outputFolder * is required to be set
73
+ ##### Glob
71
74
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
+ ```
73
80
74
- #### outputFolder
81
+ ##### Multiple destinations
75
82
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
77
90
78
91
``` js
79
92
copy ({
80
- targets: [' src/assets' , ' src/index.html' ],
81
- outputFolder: ' dist/public'
93
+ targets: [{ src: ' src/app.html' , dest: ' dist/public' , rename: ' index.html' }]
82
94
})
83
95
```
84
96
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
+ ```
86
108
87
109
#### verbose
88
110
89
- Output copied files and folders to console. Default is ` false ` .
111
+ Type: ` boolean ` | Default: ` false `
112
+
113
+ Output copied items to console.
90
114
91
115
``` js
92
116
copy ({
93
- targets: [' src/assets' , ' src/index.html' ],
94
- outputFolder: ' dist' ,
117
+ targets: [{ src: ' assets/*' , dest: ' dist/public' }],
95
118
verbose: true
96
119
})
97
120
```
98
121
99
- #### warnOnNonExist
122
+ #### hook
100
123
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.
102
127
103
128
``` js
104
129
copy ({
105
- targets: [' src/assets' , ' src/index.html' ],
106
- outputFolder: ' dist' ,
107
- warnOnNonExist: true
130
+ targets: [{ src: ' assets/*' , dest: ' dist/public' }],
131
+ hook: ' buildStart'
108
132
})
109
133
```
110
134
111
- #### hook
135
+ #### copyOnce
136
+
137
+ Type: ` boolean ` | Default: ` false `
112
138
113
- Set which rollup hook the plugin should use. Default is ` buildEnd ` .
139
+ Copy items once. Useful in watch mode .
114
140
115
141
``` js
116
142
copy ({
117
- targets: [' src/assets' , ' src/index.html' ],
118
- outputFolder: ' dist' ,
119
- hook: ' generateBundle'
143
+ targets: [{ src: ' assets/*' , dest: ' dist/public' }],
144
+ copyOnce: true
120
145
})
121
146
```
122
147
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 )
124
151
125
152
## Original Author
126
153
0 commit comments