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
Copy file name to clipboardExpand all lines: README.md
+67-64Lines changed: 67 additions & 64 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@
14
14
15
15
# copy-webpack-plugin
16
16
17
-
Copies individual files or entire directories, which already exist, to the build directory.
17
+
Copies existing individual files or entire directories to the build directory.
18
18
19
19
## Getting Started
20
20
@@ -36,7 +36,7 @@ or
36
36
pnpm add -D copy-webpack-plugin
37
37
```
38
38
39
-
Then add the plugin to your `webpack`config. For example:
39
+
Then add the plugin to your `webpack`configuration. For example:
40
40
41
41
**webpack.config.js**
42
42
@@ -57,22 +57,22 @@ module.exports = {
57
57
58
58
> [!NOTE]
59
59
>
60
-
> `copy-webpack-plugin` is not designed to copy files generated from the build process; rather, it is to copy files that already exist in the source tree, as part of the build process.
60
+
> `copy-webpack-plugin` is not designed to copy files generated during the build process. Instead, it is meant to copy files that already exist in the source tree, as part of the build process.
61
61
62
62
> [!NOTE]
63
63
>
64
-
> If you want `webpack-dev-server` to write files to the output directory during development, you can force it with the [`writeToDisk`](https://github.com/webpack/webpack-dev-middleware#writetodisk) option or the [`write-file-webpack-plugin`](https://github.com/gajus/write-file-webpack-plugin).
64
+
> If you want `webpack-dev-server` to write files to the output directory during development, you can enable the [`writeToDisk`](https://github.com/webpack/webpack-dev-middleware#writetodisk) option or use the [`write-file-webpack-plugin`](https://github.com/gajus/write-file-webpack-plugin).
65
65
66
66
> [!NOTE]
67
67
>
68
-
> You can get the original source filename from [Asset Objects](https://webpack.js.org/api/stats/#asset-objects).
68
+
> You can get the original source filename from the [Asset Objects](https://webpack.js.org/api/stats/#asset-objects) in the webpack stats API.
69
69
70
70
## Options
71
71
72
72
-**[`patterns`](#patterns)**
73
73
-**[`options`](#options-1)**
74
74
75
-
The plugin's signature:
75
+
The plugin's usage:
76
76
77
77
**webpack.config.js**
78
78
@@ -84,7 +84,7 @@ module.exports = {
84
84
newCopyPlugin({
85
85
patterns: [
86
86
{ from:"source", to:"dest" },
87
-
"path/to/source", //absolute or relative, files/directories/globs - see below for examples
87
+
"path/to/source", //Absolute or relative path, can be files, directories or globs. See examples below.
> 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.
129
-
> On Windows, the forward slash and the backward slash are both separators.
130
-
> Instead please use `/`.
128
+
> Don't use directly `\\` in `from` option if it is a `glob` (i.e `path\to\file.ext`) option, as backslashes are treated as regular characters on UNIX systems(not as path separators).
129
+
> On Windows, both forward slashes and backslashes act as separators.
130
+
> Use `/` instead, or use Node's `path` utilities to normalize paths.
131
131
132
132
**webpack.config.js**
133
133
@@ -157,7 +157,7 @@ module.exports = {
157
157
158
158
##### `For windows`
159
159
160
-
If you define `from` as absolute file path or absolute folder path on `Windows`, you can use windows path segment (`\\`)
160
+
If you're using an absolute file or folder path in the `from` option on `Windows`, you can use windows path segment (`\\`)
161
161
162
162
```js
163
163
module.exports= {
@@ -173,8 +173,8 @@ module.exports = {
173
173
};
174
174
```
175
175
176
-
But you should always use forward-slashes in `glob` expressions
177
-
See [fast-glob manual](https://github.com/mrmlnc/fast-glob#how-to-write-patterns-on-windows).
176
+
However, when writing `glob` expressions, always use forward slashes.
177
+
See the [fast-glob manual](https://github.com/mrmlnc/fast-glob#how-to-write-patterns-on-windows) for more details.
178
178
179
179
```js
180
180
module.exports= {
@@ -194,8 +194,8 @@ module.exports = {
194
194
};
195
195
```
196
196
197
-
The `context`behaves differently depending on what the `from` is (`glob`, `file` or `dir`).
198
-
More [`examples`](#examples)
197
+
The behavior of the `context`option varies depending on whether the `from`value is a `glob`, `file` or `dir`.
> Don't use directly `\\` in `to` (i.e `path\to\dest`) option because on UNIX the backslash is a valid character inside a path component, i.e., it's not a separator.
219
-
> On Windows, the forward slash and the backward slash are both separators.
220
-
> Instead please use `/` or `path`methods.
218
+
> Don't use directly `\\` in the `to`path (i.e `path\to\dest`) option, as backslashes are treated as regular characters on UNIX systems(not as path separators).
219
+
> On Windows, both forward slashes and backslashes act as separators.
220
+
> Use `/`instead, or use Node's `path`utilities to normalize paths.
221
221
222
222
**webpack.config.js**
223
223
@@ -250,9 +250,9 @@ Allows to modify the writing path.
250
250
251
251
> [!WARNING]
252
252
>
253
-
> Don't return directly `\\` in `to` (i.e `path\to\newFile`) option because on UNIX the backslash is a valid character inside a path component, i.e., it's not a separator.
254
-
> On Windows, the forward slash and the backward slash are both separators.
255
-
> Instead please use `/` or `path`methods.
253
+
> Don't use directly `\\` in `to` (i.e `path\to\newFile`) option, as backslashes are treated as regular characters on UNIX systems(not as path separators).
254
+
> On Windows, both forward slashes and backslashes act as separators.
255
+
> Use `/`instead, or use Node's `path`utilities to normalize paths.
A path to be (1) prepended to `from` and (2) removed from the start of the result path(s).
305
+
Defines the base directory used for two purposes:
306
+
307
+
1. It is prepended to the `from` path.
308
+
309
+
2. It is removed from the beginning of the result path(s).
306
310
307
311
> [!WARNING]
308
312
>
309
-
> Don't use directly `\\` in `context` (i.e `path\to\context`) option because on UNIX the backslash is a valid character inside a path component, i.e., it's not a separator.
310
-
> On Windows, the forward slash and the backward slash are both separators.
311
-
> Instead please use `/` or `path`methods.
313
+
> Don't use directly `\\` in `to` (i.e `path\to\newFile`) option, as backslashes are treated as regular characters on UNIX systems(not as path separators).
314
+
> On Windows, both forward slashes and backslashes act as separators.
315
+
> Use `/`instead, or use Node's `path`utilities to normalize paths.
312
316
313
317
**webpack.config.js**
314
318
@@ -328,21 +332,21 @@ module.exports = {
328
332
};
329
333
```
330
334
331
-
`context` can be an absolute path or a relative path. If it is a relative path, then it will be converted to an absolute path based on `compiler.options.context`.
335
+
The `context` can be an absolute or relative path. If it's relative, then it will be converted to an absolute path based on `compiler.options.context`.
332
336
333
-
`context` should be explicitly set only when `from`contains a glob. Otherwise, `context` is automatically set, based on whether `from` is a file or a directory:
337
+
You should explicitly define `context` when `from`uses a glob pattern. Otherwise, the plugin sets it automatically based on the nature of `from`:
334
338
335
-
If `from` is a file, then `context`is its directory. The result path will be the filename alone.
339
+
-If `from` is a file, then `context`defaults to the file’s directory. The result path will be just the filename alone.
336
340
337
-
If `from` is a directory, then `context`equals `from`. The result paths will be the paths of the directory's contents (including nested contents), relative to the directory.
341
+
-If `from` is a directory, `context`is set to the same directory. The result paths include the directory’s contents (including subdirectories), relative to it.
338
342
339
343
The use of `context` is illustrated by these [`examples`](#examples).
340
344
341
345
#### `globOptions`
342
346
343
347
> [!WARNING]
344
348
>
345
-
> The _onlyDirectories_ does not work because the plugin is designed to copy files.
349
+
> The _onlyDirectories_ does not work because the plugin is designed to copy files, not directories alone.
346
350
347
351
Type:
348
352
@@ -352,8 +356,8 @@ type globOptions = import("tinyglobby").GlobOptions;
352
356
353
357
Default: `undefined`
354
358
355
-
Allows to configure the glob pattern matching library used by the plugin. [See the list of supported options][glob-options]
356
-
To exclude files from the selection, you should use [globOptions.ignore option](https://github.com/mrmlnc/fast-glob#ignore)
359
+
Allows you to configure the glob pattern matching library used by the plugin. [See the list of supported options][glob-options]
360
+
To exclude files from being copied, use the[globOptions.ignore option](https://github.com/mrmlnc/fast-glob#ignore)
357
361
358
362
**webpack.config.js**
359
363
@@ -388,7 +392,7 @@ Default: `undefined`
388
392
389
393
> [!NOTE]
390
394
>
391
-
> To ignore files by path please use the [`globOptions.ignore`](#globoptions) option.
395
+
> To ignore files by path (e.g., by extension or name), prefer using the [`globOptions.ignore`] option.
|**[`transformer`](#transformer)**|`undefined`| Allows you to modify the contents of the file. |
621
+
|**[`cache`](#cache)**|`false`|Enables caching for `transform`. You can use `transform: { cache: { key: 'my-cache-key' } }` to manually invalidate the cache when needed. |
619
622
620
623
###### `transformer`
621
624
@@ -702,8 +705,8 @@ Default: `false`
702
705
703
706
**webpack.config.js**
704
707
705
-
Enable/disable and configure caching.
706
-
Default path to cache directory: `node_modules/.cache/copy-webpack-plugin`.
708
+
Enable or disable caching and configure its behavior.
709
+
By default, the cache directory is located at: `node_modules/.cache/copy-webpack-plugin`.
707
710
708
711
###### `boolean`
709
712
@@ -851,11 +854,11 @@ type transformAll = (
851
854
852
855
Default: `undefined`
853
856
854
-
Allows you to modify the contents of multiple files and save the result to one file.
857
+
Allows you to modify the contents of multiple files and save the combined result into a single file.
855
858
856
859
> [!NOTE]
857
860
>
858
-
> The `to` option must be specified and point to a file. It is allowed to use only `[contenthash]` and `[fullhash]` template strings.
861
+
> The `to` option must be specified and point to a file. Only the `[contenthash]` and `[fullhash]` template strings are allowed in the filename.
859
862
860
863
**webpack.config.js**
861
864
@@ -867,7 +870,7 @@ module.exports = {
867
870
{
868
871
from:"src/**/*.txt",
869
872
to:"dest/file.txt",
870
-
// The `assets` argument is an assets array for the pattern.from ("src/**/*.txt")
873
+
// The `assets` argument is an array of assets matched by the pattern `from` ("src/**/*.txt")
0 commit comments