templated-license-webpack-plugin v0.3.2
Templated License Webpack Plugin
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.
Installation
npm install templated-license-webpack-plugin --save-dev
Usage
First, import the plugin into your webpack configuration:
var TemplatedLicenseWebpackPlugin = require('templated-license-webpack-plugin');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.
new TemplatedLicenseWebpackPlugin({
pattern: /^(MIT|ISC|BSD.*)$/,
unacceptablePattern: /GPL/,
abortOnUnacceptableLicense: true,
licenseTemplate: (mod) => `${mod.name} v${mod.version} (${mod.url})\n\n${mod.licenseText}`
});Below are all options that can be passed to the plugin:
licenseTemplateA function that takes in module information and returns the license string to be inserted into the filepatternA regular expression of license names to match. The license is read from thelicenseproperty inpackage.jsonfor each module used in your webpack output.unacceptablePatternA regular expression of license names that are unacceptable for the build.abortOnUnacceptableLicenseUsed only in conjunction with theunacceptablePatternoption, setting this totruewill cause the plugin to throw an error and abort the build if an unacceptable license is found.filenameThis is the output filename which gets written your webpack build directory. The default is3rdpartylicenses.txt.includeUndefinedwhether include packages without license or not. The default isfalseaddLicenseTextwhether include license text to output file or not. The default istrueaddUrlwhether include url to repository to output file or not. The default isfalselicenseFilenamesA list of license filenames to match, in order of priority. The default is['LICENSE', 'LICENSE.md', 'LICENSE.txt', 'license', 'license.md', 'license.txt']licenseTemplateDirDirectory containing .txt files corresponding to SPDX license identifiers. This directory is referred to when the plugin cannot find a license file per thelicenseFilenamesproperty. Typically you would clone the SPDX master files repository and use the resulting directory containing all the various license.txtas thelicenseTemplateDirfor the plugin.licenseOverridesAn object whose keys are module names and values are filenames to use for the license file. Used when you want to override a license file for a particular module.licenseTypeOverridesAn object whose keys are module names and values are SPDX license identifier strings (e.g.'MIT'). Allows you to override the license type for any module.suppressErrors(default:false) Set totrueto avoid having the plugin write error messages to the console
If a license file cannot be found and includeUndefined property is set to false,
the plugin will write whatever the license property contains in the module's package.json and print an error.