UNPKG

3.11 kBMarkdownView Raw
1# esbuild-plugin-mxn-copy
2
3[![npm@latest](https://badgen.net/npm/v/esbuild-plugin-mxn-copy)](https://www.npmjs.com/package/esbuild-plugin-mxn-copy)
4[![Install size](https://packagephobia.now.sh/badge?p=esbuild-plugin-mxn-copy)](https://packagephobia.now.sh/result?p=esbuild-plugin-mxn-copy)
5[![Downloads](https://img.shields.io/npm/dm/esbuild-plugin-mxn-copy.svg)](https://npmjs.com/esbuild-plugin-mxn-copy)
6
7A Esbuild plugin for copying assets into the output directory of your bundle
8
9- ~12.7kb size
10
11## Install
12
13```
14$ npm install --save-dev esbuild-plugin-mxn-copy
15```
16
17## Usage
18
19Suppose we have a bunch of assets in `./src` directory:
20
21```bash
22# ls -1 ./src
23index.html
24index.js
25logo.svg
26preact
27```
28
29We want some of these files to be copied over into the output folder of our esbuild bundle.
30
31Create a `esbuild.config.js` [build script file](https://esbuild.github.io/getting-started/#build-scripts) and import the plugin:
32
33```js
34// esbuild.config.js
35import { build } from "esbuild";
36import esbuildMxnCopy from "esbuild-plugin-mxn-copy";
37// ... other imports, etc ...
38
39build({
40 entryPoints: {
41 bundle: "src/index.js"
42 },
43 bundle: true,
44 minify: false,
45 sourcemap: true,
46 outdir: "dist",
47 // ...
48 plugins: [
49 esbuildMxnCopy({
50 copy: [
51 // You can include files & directories
52 { from: "src/index.html", to: "dist/index.html" },
53 { from: "src/logo.svg", to: "dist/" },
54 { from: "src/preact", to: "dist/preact" }
55 ],
56 verbose: true
57 })
58 ],
59 // ...
60})
61.catch((e) => console.error(e.message));
62```
63
64Then call `node esbuild.config.js` or add a build script to your `package.json` file like this:
65
66```json
67{
68 "scripts": {
69 "build": "node esbuild.config.js"
70 }
71}
72```
73
74The build script can now be invoked like this:
75
76```
77$ npm run build
78```
79
80On final bundle generation the provided files will be copied over into the output folder of your rollup bundle, maintaining the original hierarchy and relativity to the input file.
81
82## Options
83
84This plugin has the following configuration options:
85
86| Property | Description | Default |
87|---------------|----------------|--------------|
88| `copy` | An array of objects with paths to files or directories to copy `from` source `to` destination. | `[]` |
89| `verbose` | This option will output additional information about operations being performed. | `false` |
90| `restrictive` | Enabling this option restricts access to all directories, except for input and output. | `false` |
91
92## License
93
94This module is released under the MIT license.
95
96## Related
97
98- [rollup-plugin-mxn-copy](https://github.com/ZimNovich/rollup-plugin-mxn-copy) - Rollup plugin for copying assets into the output directory of your bundle
99- [rollup-plugin-mxn-jsx](https://github.com/ZimNovich/rollup-plugin-mxn-jsx) - Rollup JSX plugin that transpiles JSX into JavaScript
100- [rollup-plugin-mxn-svg](https://github.com/ZimNovich/rollup-plugin-mxn-svg) - Rollup plugin that imports SVG files as JSX components