You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> ⚠️ Don't use directly `\\` in `from` (i.e `path\to\file.ext`) option because on UNIX the backslash is a valid character inside a path component, i.e., it's not a separator.
100
+
> ⚠️ Don't use directly `\\` in `from`option if it is a `glob`(i.e `path\to\file.ext`) option because on UNIX the backslash is a valid character inside a path component, i.e., it's not a separator.
101
101
> On Windows, the forward slash and the backward slash are both separators.
102
-
> Instead please use `/` or `path` methods.
102
+
> Instead please use `/`.
103
103
104
104
**webpack.config.js**
105
105
@@ -109,13 +109,18 @@ module.exports = {
109
109
newCopyPlugin({
110
110
patterns: [
111
111
'relative/path/to/file.ext',
112
-
'/absolute/path/to/file.ext',
113
112
'relative/path/to/dir',
114
-
'/absolute/path/to/dir',
113
+
path.resolve(__dirname, 'src', 'file.ext'),
114
+
path.resolve(__dirname, 'src', 'dir'),
115
115
'**/*',
116
116
{
117
117
from:'**/*',
118
118
},
119
+
// If absolute path is a `glob` we replace backslashes with forward slashes, because only forward slashes can be used in the `glob`
To exclude files from the selection, you should use [globOptions.ignore option](https://github.com/mrmlnc/fast-glob#ignore)
167
-
168
-
**webpack.config.js**
169
-
170
-
```js
171
-
module.exports= {
172
-
plugins: [
173
-
newCopyPlugin({
174
-
patterns: [
175
-
{
176
-
from:'**/*',
177
-
globOptions: {
178
-
ignore: ['**/file.*', '**/ignored-directory/**'],
179
-
},
180
-
},
181
-
],
182
-
}),
183
-
],
184
-
};
185
-
```
169
+
The `context` behaves differently depending on what the `from` is (`glob`, `file` or `dir`).
170
+
More [`examples`](#examples)
186
171
187
172
#### `to`
188
173
@@ -249,12 +234,27 @@ module.exports = {
249
234
};
250
235
```
251
236
237
+
The `context` option can be an absolute or relative path. If `context` is a relative, then it is converted to absolute based to `compiler.options.context`
238
+
239
+
Also, `context` indicates how to interpret the search results. Further, he is considered in this role.
240
+
241
+
To determine the structure from which the found resources will be copied to the destination folder, the `context` option is used.
242
+
243
+
If `from` is a file, then `context` is equal to the directory in which this file is located. Accordingly, the result will be only the file name.
244
+
245
+
If `from` is a directory, then `context` is the same as `from` and is equal to the directory itself. In this case, the result will be a hierarchical structure of the found folders and files relative to the specified directory.
246
+
247
+
If `from` is a glob, then regardless of the `context` option, the result will be the structure specified in the `from` option
248
+
249
+
More [`examples`](#examples)
250
+
252
251
#### `globOptions`
253
252
254
253
Type: `Object`
255
254
Default: `undefined`
256
255
257
256
Allows to configute the glob pattern matching library used by the plugin. [See the list of supported options][glob-options]
257
+
To exclude files from the selection, you should use [globOptions.ignore option](https://github.com/mrmlnc/fast-glob#ignore)
258
258
259
259
**webpack.config.js**
260
260
@@ -268,6 +268,7 @@ module.exports = {
268
268
globOptions: {
269
269
dot:true,
270
270
gitignore:true,
271
+
ignore: ['**/file.*', '**/ignored-directory/**'],
271
272
},
272
273
},
273
274
],
@@ -585,6 +586,173 @@ module.exports = {
585
586
};
586
587
```
587
588
589
+
### Examples
590
+
591
+
#### Different variants `from` (`glob`, `file` or `dir`).
If you want only content `src/directory-nested/`, you should only indicate `glob` in `from`. The path to the folder in which the search should take place, should be moved to `context`.
0 commit comments