What is license-webpack-plugin?
The license-webpack-plugin is a plugin for Webpack that helps you to manage and automate the process of handling license information for the packages included in your bundle. It can generate a license file, include license texts in your bundle, and filter packages based on their licenses.
What are license-webpack-plugin's main functionalities?
Generate a license file
This feature allows you to generate a single file that contains all the license information for the packages included in your webpack bundle. The 'outputFilename' option specifies the name of the file to be created.
new LicenseWebpackPlugin({
outputFilename: 'licenses.txt'
})
Include license texts in the bundle
With this feature, you can include the license texts directly in your webpack bundle. Setting 'perChunkOutput' to false will include all licenses in the main bundle file instead of separate chunk files.
new LicenseWebpackPlugin({
perChunkOutput: false
})
Filter packages by license type
This feature allows you to filter which packages to include based on their license type. In this example, only packages with the 'MIT' license will be included.
new LicenseWebpackPlugin({
licenseInclusionTest: (licenseType) => licenseType === 'MIT'
})
Other packages similar to license-webpack-plugin
webpack-license-plugin
Similar to license-webpack-plugin, webpack-license-plugin also helps in managing licenses for third-party dependencies. It can generate a third-party notices file including all licenses. It differs in the way it handles the output and configuration options.
license-checker-webpack-plugin
This plugin is another alternative that scans your node_modules directory to check for licenses and outputs a summary of the license information. It is less focused on bundling the licenses with the webpack output and more on reporting and compliance.
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.
:warning: SEEKING TESTERS :warning:
I am looking for some feedback on the next release, which allows more customizability. It can be installed using the next
tag as shown below:
npm install license-webpack-plugin@next --save-dev
See issue #43 for more details about the next release.
Installation
npm install license-webpack-plugin --save-dev
Usage
First, import the plugin into your webpack configuration:
var LicenseWebpackPlugin = require('license-webpack-plugin').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 any license type.
This example will also throw an error and terminate your build if it finds a
license containing GPL in it.
new LicenseWebpackPlugin({
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,
licenseFilenames: [
'LICENSE',
'LICENSE.md',
'LICENSE.txt',
'license',
'license.md',
'license.txt',
'LICENCE',
'LICENCE.md',
'LICENCE.txt',
'licence',
'licence.md',
'licence.txt'
],
perChunkOutput: true,
outputTemplate: 'output.template.ejs'),
outputFilename: '[name].licenses.txt',
suppressErrors: false,
includePackagesWithoutLicense: false,
unacceptablePattern: undefined,
abortOnUnacceptableLicense: false,
addBanner: false,
bannerTemplate:
'/*! 3rd party license information is available at <%- filename %> */',
includedChunks: [],
excludedChunks: [],
additionalPackages: [],
buildRoot: undefined,
modulesDirectories: ['node_modules'],
licenseTemplateDir: undefined,
licenseFileOverrides: undefined,
licenseTypeOverrides: undefined
}
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 @import
statements before the css is provided to webpack. Thus webpack (and this plugin) will have no way to tell what css files were imported. You can work around this by directly importing css from node_modules inside a javascript file. Alternatively, you can force a particular module to be in the output for all chunks by using the additionalPackages
option.
Build Instructions
npm install
npm run build
Migration Guides
Migration guides for breaking changes are documented at MIGRATION.md.
License
ISC