Skip to content

Commit 6a855e2

Browse files
authored
docs: fix typos and improve clarity in README.md (#801)
1 parent 0cae504 commit 6a855e2

File tree

1 file changed

+67
-64
lines changed

1 file changed

+67
-64
lines changed

README.md

Lines changed: 67 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
# copy-webpack-plugin
1616

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.
1818

1919
## Getting Started
2020

@@ -36,7 +36,7 @@ or
3636
pnpm add -D copy-webpack-plugin
3737
```
3838

39-
Then add the plugin to your `webpack` config. For example:
39+
Then add the plugin to your `webpack` configuration. For example:
4040

4141
**webpack.config.js**
4242

@@ -57,22 +57,22 @@ module.exports = {
5757

5858
> [!NOTE]
5959
>
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.
6161
6262
> [!NOTE]
6363
>
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).
6565
6666
> [!NOTE]
6767
>
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.
6969
7070
## Options
7171

7272
- **[`patterns`](#patterns)**
7373
- **[`options`](#options-1)**
7474

75-
The plugin's signature:
75+
The plugin's usage:
7676

7777
**webpack.config.js**
7878

@@ -84,7 +84,7 @@ module.exports = {
8484
new CopyPlugin({
8585
patterns: [
8686
{ 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.
8888
],
8989
options: {
9090
concurrency: 100,
@@ -120,14 +120,14 @@ type from = string;
120120
Default: `undefined`
121121

122122
Glob or path from where we copy files.
123-
Globs accept [fast-glob pattern-syntax](https://github.com/mrmlnc/fast-glob#pattern-syntax).
124-
Glob can only be a `string`.
123+
Globs follow the [fast-glob pattern-syntax](https://github.com/mrmlnc/fast-glob#pattern-syntax).
124+
Note: Globs must be a `string`.
125125

126126
> [!WARNING]
127127
>
128-
> 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.
131131
132132
**webpack.config.js**
133133

@@ -157,7 +157,7 @@ module.exports = {
157157

158158
##### `For windows`
159159

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 (`\\`)
161161

162162
```js
163163
module.exports = {
@@ -173,8 +173,8 @@ module.exports = {
173173
};
174174
```
175175

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.
178178

179179
```js
180180
module.exports = {
@@ -194,8 +194,8 @@ module.exports = {
194194
};
195195
```
196196

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`.
198+
See more [`examples`](#examples).
199199

200200
#### `to`
201201

@@ -211,13 +211,13 @@ Default: `compiler.options.output`
211211

212212
##### `string`
213213

214-
Output path.
214+
Specifies the output path.
215215

216216
> [!WARNING]
217217
>
218-
> 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.
221221
222222
**webpack.config.js**
223223

@@ -250,9 +250,9 @@ Allows to modify the writing path.
250250

251251
> [!WARNING]
252252
>
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.
256256
257257
**webpack.config.js**
258258

@@ -302,13 +302,17 @@ type context = string;
302302

303303
Default: `options.context|compiler.options.context`
304304

305-
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).
306310

307311
> [!WARNING]
308312
>
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.
312316
313317
**webpack.config.js**
314318

@@ -328,21 +332,21 @@ module.exports = {
328332
};
329333
```
330334

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`.
332336

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`:
334338

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.
336340

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 directorys contents (including subdirectories), relative to it.
338342

339343
The use of `context` is illustrated by these [`examples`](#examples).
340344

341345
#### `globOptions`
342346

343347
> [!WARNING]
344348
>
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.
346350
347351
Type:
348352

@@ -352,8 +356,8 @@ type globOptions = import("tinyglobby").GlobOptions;
352356

353357
Default: `undefined`
354358

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)
357361

358362
**webpack.config.js**
359363

@@ -388,7 +392,7 @@ Default: `undefined`
388392

389393
> [!NOTE]
390394
>
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.
392396
393397
**webpack.config.js**
394398

@@ -428,16 +432,16 @@ type toType = "dir" | "file" | "template";
428432

429433
Default: `undefined`
430434

431-
Determinate what is `to` option - directory, file or template.
435+
Determines the type of the `to` option — whether it's a directory, file, or template.
432436
Sometimes it is hard to say what is `to`, example `path/to/dir-with.ext`.
433-
If you want to copy files in directory you need use `dir` option.
434-
We try to automatically determine the `type` so you most likely do not need this option.
437+
If you want to copy files in directory you should explicitly set the type to `dir`.
438+
In most cases, the plugin will automatically determine the correct `type`, so you typically don't need to set this option manually.
435439

436-
| Name | Type | Default | Description |
437-
| :---------------------------: | :------: | :---------: | :--------------------------------------------------------------------------------------------------- |
438-
| **[`'dir'`](#dir)** | `string` | `undefined` | If `to` has no extension or ends on `'/'` |
439-
| **[`'file'`](#file)** | `string` | `undefined` | If `to` is not a directory and is not a template |
440-
| **[`'template'`](#template)** | `string` | `undefined` | If `to` contains [a template pattern](https://webpack.js.org/configuration/output/#template-strings) |
440+
| Name | Type | Default | Description |
441+
| :---------------------------: | :------: | :---------: | :---------------------------------------------------------------------------------------------------------- |
442+
| **[`'dir'`](#dir)** | `string` | `undefined` | Used `to` has no extension or ends with a `'/'`. |
443+
| **[`'file'`](#file)** | `string` | `undefined` | Used when `to` is a file path that is not a directory or template. |
444+
| **[`'template'`](#template)** | `string` | `undefined` | Used when `to` contains [a template pattern](https://webpack.js.org/configuration/output/#template-strings) |
441445

442446
##### `'dir'`
443447

@@ -509,7 +513,7 @@ type force = boolean;
509513

510514
Default: `false`
511515

512-
Overwrites files already in `compilation.assets` (usually added by other plugins/loaders).
516+
Overwrites files that already exist in `compilation.assets` (typically added by other plugins or loaders).
513517

514518
**webpack.config.js**
515519

@@ -541,8 +545,7 @@ Default: `0`
541545

542546
Allows to specify the priority of copying files with the same destination name.
543547
Files for patterns with higher priority will be copied later.
544-
To overwrite files, the [`force`](#force) option must be enabled.
545-
548+
To enable overwriting, the [`force`](#force) option must be set to `true`.
546549
**webpack.config.js**
547550

548551
```js
@@ -584,7 +587,7 @@ type transform =
584587

585588
Default: `undefined`
586589

587-
Allows to modify the file contents.
590+
Allows you to modify the contents of a file before it is written to the output directory.
588591

589592
##### `function`
590593

@@ -612,10 +615,10 @@ module.exports = {
612615

613616
##### `object`
614617

615-
| Name | Default | Description |
616-
| :-------------------------------: | :---------: | :--------------------------------------------------------------------------------------------------------------- |
617-
| **[`transformer`](#transformer)** | `undefined` | Allows to modify the file contents. |
618-
| **[`cache`](#cache)** | `false` | Enable `transform` caching. You can use `transform: { cache: { key: 'my-cache-key' } }` to invalidate the cache. |
618+
| Name | Default | Description |
619+
| :-------------------------------: | :---------: | :----------------------------------------------------------------------------------------------------------------------------------------- |
620+
| **[`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. |
619622

620623
###### `transformer`
621624

@@ -702,8 +705,8 @@ Default: `false`
702705

703706
**webpack.config.js**
704707

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`.
707710

708711
###### `boolean`
709712

@@ -851,11 +854,11 @@ type transformAll = (
851854

852855
Default: `undefined`
853856

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.
855858

856859
> [!NOTE]
857860
>
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.
859862
860863
**webpack.config.js**
861864

@@ -867,7 +870,7 @@ module.exports = {
867870
{
868871
from: "src/**/*.txt",
869872
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")
871874
transformAll(assets) {
872875
const result = assets.reduce((accumulator, asset) => {
873876
// The asset content can be obtained from `asset.source` using `source` method.
@@ -897,7 +900,7 @@ type noErrorOnMissing = boolean;
897900

898901
Default: `false`
899902

900-
Doesn't generate an error on missing file(s).
903+
Doesn't generate an error if file(s) are missing.
901904

902905
```js
903906
module.exports = {
@@ -1004,7 +1007,7 @@ module.exports = {
10041007

10051008
#### Different variants of `from` (`glob`, `file` or `dir`).
10061009

1007-
Take for example the following file structure:
1010+
Consider the following file structure:
10081011

10091012
```
10101013
src/directory-nested/deep-nested/deepnested-file.txt
@@ -1089,7 +1092,7 @@ deep-nested/deepnested-file.txt,
10891092
nested-file.txt
10901093
```
10911094

1092-
Technically, this is `**/*` with a predefined context equal to the specified directory.
1095+
Technically, this is equivalent to using `**/*` with a predefined context set to the specified directory
10931096

10941097
**webpack.config.js**
10951098

@@ -1142,7 +1145,7 @@ Result:
11421145
nested-file.txt
11431146
```
11441147

1145-
Technically, this is a filename with a predefined context equal to `path.dirname(pathToFile)`.
1148+
Technically, this is a filename with a predefined context equal to the file's directory `path.dirname(pathToFile)`.
11461149

11471150
**webpack.config.js**
11481151

@@ -1198,7 +1201,7 @@ module.exports = {
11981201

11991202
#### Flatten copy
12001203

1201-
Removes all directory references and only copies file names.
1204+
Removes all directory references and copies only file names.
12021205

12031206
> [!WARNING]
12041207
>
@@ -1286,8 +1289,8 @@ module.exports = {
12861289

12871290
##### `yarn workspaces` and `monorepos`
12881291

1289-
When using `yarn workspaces` or` monorepos`, relative copy paths from node_modules can be broken due to the way packages are hoisting.
1290-
To avoid this, should explicitly specify where to copy the files from using `require.resolve`.
1292+
When using `yarn workspaces` or` monorepos`, relative copy paths from `node_modules` can be broken due to the way packages are hoisting.
1293+
To avoid this, you should explicitly specify where to copy the files from; by using `require.resolve`.
12911294

12921295
**webpack.config.js**
12931296

0 commit comments

Comments
 (0)