|
1 | | -# esbuild plugin for copying files |
| 1 | +<div align="center"> |
2 | 2 |
|
3 | | -  |
| 3 | +<img width="196" src="https://raw.githubusercontent.com/simonkovtyk/esbuild-plugin-file-copy/611c5c4942c8460ec6247ab833418908e9213a9b/docs/esbuild-favicon.svg" /> |
4 | 4 |
|
5 | | -The plugin copies files to the esbuild out folder, ensuring that all required files are included alongside the built code. |
| 5 | +<h1>File Copy Plugin</h1> |
6 | 6 |
|
7 | | -* Supports newest esbuild version |
8 | | -* Advanced with globs |
9 | | -* Uses raw filesystem calls |
10 | | -* Uses esbuild config to determine the out folder |
11 | | -* Type declarations (d.ts) included |
| 7 | +<p>This esbuild plugin copies specified files to the output folder after the bundling process. It ensures static assets are included in the final build without interrupting or altering the main esbuild workflow.</p> |
12 | 8 |
|
13 | | -## How It Works |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
14 | 13 |
|
15 | | -1. Parses the file paths by globs |
16 | | -2. Creates folder for the file paths, if there are not exists. |
17 | | -3. Determines the out-folder by using the existing esbuild configuration. |
18 | | -4. Writes the files to their responsible out paths. |
| 14 | +<br /> |
19 | 15 |
|
20 | | -This plugin prefers an ``outdir`` over an ``outfile``, but if only an ``outfile`` is provided, the plugin will choose the directory of the ``outfile`` as base output directory for the files |
21 | | -instead.\ |
22 | | -The ``outbase`` is used as a prefix for the ``outdir`` or ``outfile`` and it can be left as empty, if it is not needed. |
| 16 | +Add a ⭐ to this repository — *it motivates me a lot!* |
23 | 17 |
|
24 | | -## Options |
| 18 | +</div> |
25 | 19 |
|
26 | | -### Input files to copy them |
| 20 | +## ⚡️ Getting started |
27 | 21 |
|
28 | | -Files can be provided as glob.\ |
29 | | -[See here for more about the syntax of globs.](https://github.com/mrmlnc/fast-glob?tab=readme-ov-file#pattern-syntax) |
| 22 | +Simply install this package with your package manager. |
30 | 23 |
|
31 | | -#### Simple including |
32 | | - |
33 | | -It is possible to provide globs only as ``string``: |
34 | | -````typescript |
35 | | -fileCopyPlugin({ |
36 | | - inputs: [ |
37 | | - "src/**/README.md" |
38 | | - ] |
39 | | -}) |
| 24 | +````shell |
| 25 | +npm install -D esbuild-plugin-file-copy |
40 | 26 | ```` |
41 | 27 |
|
42 | | -In this case, the output directory of the matching files is the output directory of the esbuild configuration, because no output directory else was specified. |
| 28 | +<details> |
| 29 | +<summary>📦 other package manager</summary> |
43 | 30 |
|
44 | | -If you want an option to handle the output directory of the files by yourself, you should follow the advanced including. |
| 31 | +Here are examples for installing the package with other package manager. |
45 | 32 |
|
46 | | -#### Advanced including |
| 33 | +> 💾 **yarn** |
| 34 | +> ````shell |
| 35 | +> yarn add -D esbuild-plugin-file-copy |
| 36 | +> ```` |
47 | 37 |
|
48 | | -It is also possible to provide globs as ``Object``. |
| 38 | +> 💾 **pnpm** |
| 39 | +> ````shell |
| 40 | +> pnpm install -D esbuild-plugin-file-copy |
| 41 | +> ```` |
49 | 42 |
|
50 | | -````typescript |
51 | | -fileCopyPlugin({ |
52 | | - inputs: [ |
53 | | - { |
54 | | - glob: "src/**/README.md", |
55 | | - output: "somefolder/anyfolder" |
56 | | - } |
57 | | - ] |
58 | | -}) |
59 | | -```` |
| 43 | +</details> |
| 44 | +
|
| 45 | +Looks good so far 🔥 — now you have installed the latest version! |
60 | 46 |
|
61 | | -The ``Object`` expects a key "glob" and an optional key "output". |
| 47 | +## 💡 Introduction |
62 | 48 |
|
| 49 | +This esbuild plugin simply copies specified files to the output folder during the build process. It reads a list of file paths or patterns, then moves those files into the output directory after |
| 50 | +esbuild finishes bundling. |
63 | 51 |
|
64 | | -If the key "output" is set, the output directory of the files will be the given output directory **without** the output directory of the esbuild configuration as base output directory. |
| 52 | +The plugin ensures that static assets, such as images or configuration files, are included in the final build. It’s lightweight and works without altering the bundling |
| 53 | +process itself. By automating file copying, it reduces manual steps and keeps the build process smooth and consistent. |
65 | 54 |
|
66 | | -If the key "output" is not set, the output directory will be the base output directory of the esbuild configuration. |
| 55 | +## 🔧 Usage |
67 | 56 |
|
68 | | -### Base output directory |
| 57 | +```typescript |
| 58 | +fileCopyPlugin(options); |
| 59 | +``` |
69 | 60 |
|
70 | | -This plugin will use the esbuild configuration to determine the base output directory for the files.\ |
71 | | -Sometimes it can be helpful to overwrite the base output directory. |
| 61 | +This function needs to be called inside the esbuild configuration in order to use this plugin. It will provide the plugin inside the build process of esbuild. |
| 62 | +
|
| 63 | +<details> |
| 64 | +<summary>Show an example of the integration</summary> |
72 | 65 |
|
73 | 66 | ````typescript |
74 | | -fileCopyPlugin( |
75 | | - overrideOutBase?: string | undefined, |
76 | | - overrideOutDir?: string | undefined, |
77 | | - overrideOutFile?: string | undefined |
78 | | -); |
| 67 | +esbuild.build({ |
| 68 | + // some esbuild configuration... |
| 69 | + plugins: [ |
| 70 | + fileCopyPlugin( |
| 71 | + // configure it here... |
| 72 | + ); |
| 73 | + // more esbuild plugins here... |
| 74 | + ] |
| 75 | +}) |
79 | 76 | ```` |
80 | 77 |
|
81 | | -Each overwrite will overwrite the specific esbuild configuration. |
| 78 | +</details> |
| 79 | + |
| 80 | +### Properties |
82 | 81 |
|
83 | | -[See here for more details about the out configuration of esbuild.](https://esbuild.github.io/api/#outbase) |
| 82 | +#### ``inputs`` |
84 | 83 |
|
85 | | -### Lifecycle |
| 84 | +> Default: ``undefined`` |
86 | 85 |
|
87 | | -You can configure at which lifecycle of esbuild the plugin will be called. |
| 86 | +A ``Array`` of ``object`` with the following properties: |
88 | 87 |
|
89 | 88 | ````typescript |
90 | | -fileCopyPlugin( |
91 | | - lifecycle: "onStart" | "onEnd" | "onDispose" | undefined |
92 | | -); |
| 89 | +{ |
| 90 | + from: string, |
| 91 | + to: string |
| 92 | +} |
93 | 93 | ```` |
94 | 94 |
|
95 | | -[See here for more about the esbuild lifecycles.](https://esbuild.github.io/plugins/#concepts) |
| 95 | +Any file or directory from the source path (``from`` key) will be copied to the target path (``to`` key). |
96 | 96 |
|
97 | | -## Usage |
| 97 | +The file name will be kept while copying the file from source path to target path. |
98 | 98 |
|
99 | | -### Installation |
| 99 | +<details> |
| 100 | +<summary>Show an example</summary> |
100 | 101 |
|
101 | | -The plugin can be installed by any package manager. |
| 102 | +````typescript |
| 103 | +fileCopyPlugin({ |
| 104 | + inputs: [{ |
| 105 | + from: "my-lib/example.ts", // input path |
| 106 | + to: "dist/my-lib" // copied to path |
| 107 | + }] |
| 108 | +}); |
| 109 | +```` |
102 | 110 |
|
103 | | -<details><summary><b>Show instructions</b></summary> |
| 111 | +</details> |
104 | 112 |
|
105 | | -> npm \ |
106 | | -> ``npm install esbuild-plugin-file-copy`` |
| 113 | +#### ``globs`` |
107 | 114 |
|
108 | | -> yarn \ |
109 | | -> ``yarn install esbuild-plugin-file-copy`` |
| 115 | +> Default: ``undefined`` |
110 | 116 |
|
111 | | -> pnpm \ |
112 | | -> ``pnpm install esbuild-plugin-file-copy`` |
| 117 | +A ``Array`` of ``object`` with the following properties: |
113 | 118 |
|
114 | | -</details> |
| 119 | +````typescript |
| 120 | +{ |
| 121 | + from: string, |
| 122 | + to: string |
| 123 | +} |
| 124 | +```` |
115 | 125 |
|
116 | | -### Integration |
| 126 | +Any matching file or directory from the source path (``from`` key) will be copied to the target path (``to`` key). |
117 | 127 |
|
118 | | -The easy way to integrate this plugin in esbuild. |
| 128 | +The file name will be kept while copying the file from source path to target path. |
119 | 129 |
|
120 | | -<details><summary><b>Show instructions</b></summary> |
| 130 | +This option enables the use of glob patterns. [See here](https://www.malikbrowne.com/blog/a-beginners-guide-glob-patterns/) for more about glob patterns. |
| 131 | + |
| 132 | +<details> |
| 133 | +<summary>Show an example</summary> |
121 | 134 |
|
122 | 135 | ````typescript |
123 | | -await esbuild.build({ |
124 | | - [...] |
125 | | - plugins: [ |
126 | | - fileCopyPlugin(...) |
127 | | - ] |
128 | | -}) |
| 136 | +fileCopyPlugin({ |
| 137 | + globs: [{ |
| 138 | + from: "my-lib/**/*.env", // input path |
| 139 | + to: "dist/my-lib" // copied to path |
| 140 | + }] |
| 141 | +}); |
129 | 142 | ```` |
130 | 143 |
|
131 | | -[See here for more about the esbuild plugin integration.](https://esbuild.github.io/plugins/#using-plugins) |
132 | | - |
133 | 144 | </details> |
134 | 145 |
|
| 146 | +### Returns |
| 147 | + |
| 148 | +Type: ``Plugin`` |
| 149 | + |
| 150 | +An instance of this plugin, that will be used by esbuild automatically. |
| 151 | + |
135 | 152 | ## License |
136 | 153 |
|
137 | | -The MIT License (MIT) - Please have a look at the LICENSE file for more details. |
| 154 | +The MIT License (MIT) - Please have a look at the [License](https://github.com/simonkovtyk/esbuild-plugin-file-copy/blob/main/LICENSE) file for more details. |
138 | 155 |
|
139 | 156 | ## Contributing |
140 | 157 |
|
141 | | -Feel free to contribute to this project.\ |
142 | | -You can fork this project and create a new pull request for contributing. |
| 158 | +Want to contribute to an open-source project on GitHub but unsure where to start? Check out this comprehensive step-by-step guide on how to contribute effectively! |
| 159 | + |
| 160 | +From forking the repository to creating pull requests, this guide walks you through every stage of the process, helping you make a successful contribution to this GitHub project. Start collaborating, |
| 161 | +learn new skills, and make an impact on this project! |
143 | 162 |
|
144 | | -[Get to the repository at GitHub.](https://github.com/simonkovtyk/esbuild-plugin-file-copy) |
| 163 | +[See here](https://github.com/simonkovtyk/esbuild-plugin-file-copy/blob/main/docs/guides/HOW_TO_CONTRIBUTE.md) for the contribute guide at GitHub. |
145 | 164 |
|
146 | 165 | <hr> |
147 | 166 |
|
|
0 commit comments