This webpack plugin finds all 3rd party libraries used in a webpack build whose licenses match a given regex, and outputs the licenses for each package in your webpack build directory.
npm install license-webpack-plugin --save-dev
First, import the plugin into your webpack configuration:
var LicenseWebpackPlugin = LicenseWebpackPlugin;
The plugin requires you to specify a regular expression for licenses to match under the pattern property.
To use the plugin, simply add it to your webpack config's plugin list.
The below example matches MIT, ISC, and any license starting with BSD. This example will also throw an error and terminate your build if it finds a license containing GPL in it.
pattern: /^$/unacceptablePattern: /GPL/abortOnUnacceptableLicense: true;
Below is an annotated list of options that can be passed along with their default values. Note all fields are optional unless noted otherwise.
pattern: undefined // Required. regex of licenses to include.licenseFilenames: // list of filenames to search for in each package'LICENSE''LICENSE.md''LICENSE.txt''license''license.md''license.txt'perChunkOutput: true // whether or not to generate output for each chunk, for just create one file with all the licenses combinedoutputTemplate: path // ejs template for rendering the licensesoutputFilename: '[name].licenses.txt' // output name. [name] refers to the chunk name here. Any properties of the chunk can be used here, such as [hash]. If perChunkOutput is false, the default value is 'licenses.txt'suppressErrors: false // suppress error messagesincludePackagesWithoutLicense: false // whether or not to include packages that are missing a licenseunacceptablePattern: undefined // regex of unacceptable licensesabortOnUnacceptableLicense: false // whether or not to abort the build if an unacceptable license is detectedaddBanner: false // whether or not to add a banner to the beginning of all js files in the chunk indicating where the licenses arebannerTemplate: // ejs template string of how the banner shold appear at the beginning of each js file in the chunk'/*! 3rd party license information is available at <%- filename %> */'includedChunks: // array of chunk names for which license files should be producedexcludedChunks: // array of chunk names for which license files should not be produced. If a chunk is both included and excluded, then it is ultimately excluded.additionalPackages: // array of additional packages to scan
WARNING: If you are importing css from node_modules indirectly via something like a sass
@import, the package will not appear in your list. This is because libsass processes all
npm install npm run build
Migration guides for breaking changes are documented at MIGRATION.md.