|
| 1 | +# license-checker-webpack-plugin |
1 | 2 |
|
2 |
| -# Contributing |
| 3 | +Webpack plugin that verifies licenses of all external dependencies in a compilation, and outputs all that information to a file. |
3 | 4 |
|
4 |
| -This project welcomes contributions and suggestions. Most contributions require you to agree to a |
5 |
| -Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us |
6 |
| -the rights to use your contribution. For details, visit https://cla.microsoft.com. |
| 5 | +## Installation |
7 | 6 |
|
8 |
| -When you submit a pull request, a CLA-bot will automatically determine whether you need to provide |
9 |
| -a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions |
10 |
| -provided by the bot. You will only need to do this once across all repos using our CLA. |
| 7 | +### npm |
11 | 8 |
|
12 |
| -This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). |
13 |
| -For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or |
14 |
| -contact [[email protected]](mailto:[email protected]) with any additional questions or comments. |
| 9 | +``` |
| 10 | +npm install license-checker-webpack-plugin --save-dev |
| 11 | +``` |
| 12 | + |
| 13 | +### yarn |
| 14 | + |
| 15 | +``` |
| 16 | +yarn add license-checker-webpack-plugin --dev |
| 17 | +``` |
| 18 | + |
| 19 | +## Usage |
| 20 | + |
| 21 | +Require the plugin into your Webpack configuration, and pass it to the `plugins` array. |
| 22 | + |
| 23 | +```js |
| 24 | +const LicenseCheckerWebpackPlugin = require("license-checker-webpack-plugin"); |
| 25 | + |
| 26 | +module.exports = { |
| 27 | + // ... |
| 28 | + plugins: [new LicenseCheckerWebpackPlugin({ output: "ThirdPartyNotices.txt" })] |
| 29 | +}; |
| 30 | +``` |
| 31 | + |
| 32 | +## Options |
| 33 | + |
| 34 | +| Property | Type | Default | Description | |
| 35 | +| ---------------- | ---------- | ---------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 36 | +| `allow` | `string` | `"(Apache-2.0 OR BSD-2-Clause OR BSD-3-Clause OR MIT)"` | SPDX expression with allowed licenses. | |
| 37 | +| `ignore` | `array` | `[]` | Array of dependencies to ignore, in the format `["<dependency name>@<version range>"]`. For example, `["assignment@^2.0.0"]`. | |
| 38 | +| `override` | `object` | `{}` | Object of dependencies to override, in the format `{"<dependency name>@<version range>": { ... }}`. For example, `{"assignment@^2.0.0": { licenseName: "MIT" }}`. | |
| 39 | +| `emitError` | `boolean` | `false` | Whether to emit errors instead of warnings. | |
| 40 | +| `outputWriter` | `function` | See [`defaultOutputWriter`](./src/defaultOutputWriter.js). | Function that will generate the contents of the third-party notices file. | |
| 41 | +| `outputFilename` | `string` | `"ThirdPartyNotices.txt"` | Name of the third-party notices file with all licensing information. | |
| 42 | + |
| 43 | +The data that gets passed to the `outputWriter` function looks like this: |
| 44 | + |
| 45 | +```json |
| 46 | +[ |
| 47 | + { |
| 48 | + "name": "react", |
| 49 | + "version": "16.3.2", |
| 50 | + "repository": "git+https://github.com/facebook/react.git", |
| 51 | + "licenseName": "MIT", |
| 52 | + "licenseText": "MIT License\n\nCopyright (c) 2013-present, Facebook, Inc. [...]" |
| 53 | + }, |
| 54 | + { |
| 55 | + "name": "webpack", |
| 56 | + "version": "4.8.3", |
| 57 | + "author": "Tobias Koppers @sokra", |
| 58 | + "repository": "git+https://github.com/webpack/webpack.git", |
| 59 | + "licenseName": "MIT", |
| 60 | + "licenseText": "Copyright JS Foundation and other contributors [...]" |
| 61 | + }, |
| 62 | + { |
| 63 | + "name": "whatwg-fetch", |
| 64 | + "version": "2.0.4", |
| 65 | + "repository": "git+https://github.com/github/fetch.git", |
| 66 | + "licenseName": "MIT", |
| 67 | + "licenseText": "Copyright (c) 2014-2016 GitHub, Inc. [...]" |
| 68 | + } |
| 69 | +] |
| 70 | +``` |
| 71 | + |
| 72 | +Here's an example `webpack.config.js` file that uses all options: |
| 73 | + |
| 74 | +```js |
| 75 | +const LicenseCheckerWebpackPlugin = require("license-checker-webpack-plugin"); |
| 76 | +const template = require("lodash.template"); |
| 77 | + |
| 78 | +const customTemplate = templaet(readFileSync("customTemplate.ejs")); |
| 79 | + |
| 80 | +module.exports = { |
| 81 | + // ... |
| 82 | + plugins: [ |
| 83 | + new LicenseCheckerWebpackPlugin({ |
| 84 | + allow: "(Apache-2.0 OR BSD-2-Clause OR BSD-3-Clause OR MIT)", |
| 85 | + ignore: ["@microsoft/*"], |
| 86 | + override: { |
| 87 | + "[email protected]": { licenseName : "MIT" }, |
| 88 | + "[email protected]": { licenseName : "MIT" }, |
| 89 | + "[email protected]": { licenseName : "MIT" } |
| 90 | + }, |
| 91 | + emitError: true, |
| 92 | + outputWriter: data => customTemplate(data), |
| 93 | + outputFilename: "ThirdPartyNotices.txt" |
| 94 | + }) |
| 95 | + ] |
| 96 | +}; |
| 97 | +``` |
| 98 | + |
| 99 | +## Contributing |
| 100 | + |
| 101 | +This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit <https://cla.microsoft.com>. |
| 102 | + |
| 103 | +When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA. |
| 104 | + |
| 105 | +This project has adopted the [Microsoft Open Source Code of Conduct ](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [[email protected]](mailto:[email protected]) with any additional questions or comments. |
| 106 | + |
| 107 | +## Licensing |
| 108 | + |
| 109 | +All files on this repository are subject to the MIT license. Please read the `LICENSE` file at the root of the project. |
0 commit comments