|
1 |
| -# esbuild-plugin-package-json |
2 |
| -Prepares the package.json by removing all unnecessary fields and copying it to the out folder of esbuild, so the built package can be published directly. |
| 1 | +# esbuild plugin for package.json |
| 2 | + |
| 3 | +  |
| 4 | + |
| 5 | +Prepares the package.json by removing all unnecessary fields and copying it to the out-folder of esbuild, so the built package can be published directly. |
| 6 | + |
| 7 | +* Supports newest esbuild version |
| 8 | +* Uses NPM's package.json discovery |
| 9 | +* Uses esbuild config to determine the out folder |
| 10 | +* Type declarations (d.ts) included |
| 11 | + |
| 12 | +## Unnecessary fields |
| 13 | + |
| 14 | +While a package should be published, there are a few fields, that may are considered as a security vulnerability or are just not needed in the published package. |
| 15 | + |
| 16 | +Following fields will be removed: |
| 17 | +- devDependencies |
| 18 | +- scripts |
| 19 | + |
| 20 | +## How It Works |
| 21 | + |
| 22 | +1. Parses the package.json from the project root. |
| 23 | +2. Deletes all unnecessary fields. |
| 24 | +3. Determines the out-folder by using the existing esbuild configuration. |
| 25 | +4. Writes the new package.json to this dir. |
| 26 | + |
| 27 | +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 output directory for the package.json instead.\ |
| 28 | +The ``outbase`` is used as a prefix for the ``outdir`` or ``outfile`` and it can be left as empty, if it is not needed. |
| 29 | + |
| 30 | +## Options |
| 31 | + |
| 32 | +### Parsing the package.json file |
| 33 | + |
| 34 | +The default behavior is, that this package will use NPM's package.json resolution.\ |
| 35 | +Otherwise it may be helpful, to overwrite the path to the package.json manually: |
| 36 | + |
| 37 | +```typescript |
| 38 | +packageJsonPlugin( |
| 39 | + [...] |
| 40 | + pathToPackageJson?: string | undefined |
| 41 | +); |
| 42 | +``` |
| 43 | + |
| 44 | +The path to the custom package.json can be customized by using the ``pathToPackageJson`` key. |
| 45 | + |
| 46 | +### Output directory |
| 47 | + |
| 48 | +This plugin will use the esbuild configuration to determine the output directory for the package.json.\ |
| 49 | +Sometimes it can be helpful to overwrite the output directory. |
| 50 | + |
| 51 | +````typescript |
| 52 | +packageJsonPlugin( |
| 53 | + [...] |
| 54 | + overrideOutBase?: string | undefined, |
| 55 | + overrideOutDir?: string | undefined, |
| 56 | + overrideOutFile?: string | undefined |
| 57 | +); |
| 58 | +```` |
| 59 | + |
| 60 | +Each overwrite will overwrite the specific esbuild configuration. |
| 61 | + |
| 62 | +[See here for more details about the out configuration of esbuild.](https://esbuild.github.io/api/#outbase) |
| 63 | + |
| 64 | +### Lifecycle |
| 65 | + |
| 66 | +You can configure at which lifecycle of esbuild, where the plugin will be called. |
| 67 | + |
| 68 | +````typescript |
| 69 | +packageJsonPlugin( |
| 70 | + [...] |
| 71 | + lifecycle: "onStart" | "onEnd" | "onDispose" | undefined |
| 72 | +); |
| 73 | +```` |
| 74 | + |
| 75 | +[See here for more about the esbuild lifecycles.](https://esbuild.github.io/plugins/#concepts) |
| 76 | + |
| 77 | +## Usage |
| 78 | + |
| 79 | +### Installation |
| 80 | + |
| 81 | +The plugin can be installed by any package manager. |
| 82 | + |
| 83 | +<details><summary><b>Show instructions</b></summary> |
| 84 | + |
| 85 | +> npm \ |
| 86 | +> ``npm install esbuild-plugin-package-json`` |
| 87 | +
|
| 88 | +> yarn \ |
| 89 | +> ``yarn install esbuild-plugin-package-json`` |
| 90 | +
|
| 91 | +> pnpm \ |
| 92 | +> ``pnpm install esbuild-plugin-package-json`` |
| 93 | +
|
| 94 | +</details> |
| 95 | + |
| 96 | +### Integration |
| 97 | + |
| 98 | +The easy way to integrate this plugin in esbuild. |
| 99 | + |
| 100 | +<details><summary><b>Show instructions</b></summary> |
| 101 | + |
| 102 | +````typescript |
| 103 | +await esbuild.build({ |
| 104 | + [...] |
| 105 | + plugins: [ |
| 106 | + packageJsonPlugin(...) |
| 107 | + ] |
| 108 | +}) |
| 109 | +```` |
| 110 | + |
| 111 | +[See here for more about the esbuild plugin integration.](https://esbuild.github.io/plugins/#using-plugins) |
| 112 | + |
| 113 | +</details> |
| 114 | + |
| 115 | +## License |
| 116 | + |
| 117 | +The MIT License (MIT) - Please have a look at the LICENSE file for more details. |
| 118 | + |
| 119 | +## Contributing |
| 120 | + |
| 121 | +Feel free to contribute to this project.\ |
| 122 | +You can fork this project and create a new pull request for contributing. |
| 123 | + |
| 124 | +[Get to the repository at GitHub.](https://github.com/simonkovtyk/esbuild-plugin-package-json) |
| 125 | + |
| 126 | +<hr> |
| 127 | + |
| 128 | +GitHub [@simonkovtyk](https://github.com/simonkovtyk) |
0 commit comments