\hypertarget{md_sfcode_node_modules_license_webpack_plugin_DOCUMENTATION_autotoc_md16091}{}\doxysection{Basic Setup}\label{md_sfcode_node_modules_license_webpack_plugin_DOCUMENTATION_autotoc_md16091}
Below is an example of how to add the plugin to a webpack config\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{const LicenseWebpackPlugin = require('license-\/webpack-\/plugin').LicenseWebpackPlugin;}
\DoxyCodeLine{}
\DoxyCodeLine{module.exports = \{}
\DoxyCodeLine{  plugins: [}
\DoxyCodeLine{    new LicenseWebpackPlugin()}
\DoxyCodeLine{  ]}
\DoxyCodeLine{\}; }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_license_webpack_plugin_DOCUMENTATION_autotoc_md16092}{}\doxysection{Configuration}\label{md_sfcode_node_modules_license_webpack_plugin_DOCUMENTATION_autotoc_md16092}

\begin{DoxyItemize}
\item $\ast$$\ast${\ttfamily stats}$\ast$$\ast$ -\/ toggle warnings and errors on/off (default\+: report warnings and errors)
\end{DoxyItemize}

Example\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{new LicenseWebpackPlugin(\{}
\DoxyCodeLine{  stats: \{}
\DoxyCodeLine{    warnings: true,}
\DoxyCodeLine{    errors: true}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\}); }

\end{DoxyCode}



\begin{DoxyItemize}
\item $\ast$$\ast${\ttfamily license\+Inclusion\+Test}$\ast$$\ast$ -\/ filter which licenses get included in the report (default\+: capture all licenses)
\end{DoxyItemize}

Example\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{new LicenseWebpackPlugin(\{}
\DoxyCodeLine{  licenseInclusionTest: (licenseType) => (licenseType === 'MIT')}
\DoxyCodeLine{\}); }

\end{DoxyCode}


Notes\+: All license identifiers in npm packages are supposed to follow SPDX format. If your requirements are very specific, it is recommended to set up this option using the \href{https://www.npmjs.com/package/spdx-satisfies}{\texttt{ {\ttfamily spdx-\/satisfies}}} package. The plugin does not provide the {\ttfamily spdx-\/satisfies} package, so you must install it separately if you want to use it.

Example using {\ttfamily spdx-\/satisfies}\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{const satisfies = require('spdx-\/satisfies');}
\DoxyCodeLine{}
\DoxyCodeLine{new LicenseWebpackPlugin(\{}
\DoxyCodeLine{  licenseInclusionTest: (licenseType) => satisfies(licenseType, '(ISC OR MIT)')}
\DoxyCodeLine{\}); }

\end{DoxyCode}



\begin{DoxyItemize}
\item $\ast$$\ast${\ttfamily output\+Filename}$\ast$$\ast$ -\/ customize the license report filename (default\+: `'\mbox{[}name\mbox{]}.licenses.\+txt\textquotesingle{}\`{})
\end{DoxyItemize}

Example\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{new LicenseWebpackPlugin(\{}
\DoxyCodeLine{  outputFilename: '[name].[hash].licenses.txt'}
\DoxyCodeLine{\}); }

\end{DoxyCode}



\begin{DoxyItemize}
\item $\ast$$\ast${\ttfamily unacceptable\+License\+Test}$\ast$$\ast$ -\/ error out on unacceptable license (default\+: disabled)
\end{DoxyItemize}

Example\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{new LicenseWebpackPlugin(\{}
\DoxyCodeLine{  unacceptableLicenseTest: (licenseType) => (licenseType === 'GPL')}
\DoxyCodeLine{\}); }

\end{DoxyCode}



\begin{DoxyItemize}
\item $\ast$$\ast${\ttfamily handle\+Unacceptable\+License}$\ast$$\ast$ -\/ do something when an unacceptable license is found (default\+: disabled)
\end{DoxyItemize}

Example\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{new LicenseWebpackPlugin(\{}
\DoxyCodeLine{  unacceptableLicenseTest: (licenseType) => (licenseType === 'GPL'),}
\DoxyCodeLine{  handleUnacceptableLicense: (packageName, licenseType) => \{}
\DoxyCodeLine{    // do something here}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\}); }

\end{DoxyCode}



\begin{DoxyItemize}
\item $\ast$$\ast${\ttfamily excluded\+Package\+Test}$\ast$$\ast$ -\/ exclude packages (default\+: disabled)
\end{DoxyItemize}

Example\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{new LicenseWebpackPlugin(\{}
\DoxyCodeLine{  excludedPackageTest: (packageName) => packageName === 'excluded-\/package'}
\DoxyCodeLine{\}); }

\end{DoxyCode}



\begin{DoxyItemize}
\item $\ast$$\ast${\ttfamily per\+Chunk\+Output}$\ast$$\ast$ -\/ control whether or not the license files are generated per chunk or are combined into one file (default\+: {\ttfamily true})
\end{DoxyItemize}

Example\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{new LicenseWebpackPlugin(\{}
\DoxyCodeLine{  perChunkOutput: false // combine all license information into one file}
\DoxyCodeLine{\}); }

\end{DoxyCode}



\begin{DoxyItemize}
\item $\ast$$\ast${\ttfamily add\+Banner}$\ast$$\ast$ -\/ write a banner to the top of each js file (default\+: {\ttfamily false})
\end{DoxyItemize}

Example\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{new LicenseWebpackPlugin(\{}
\DoxyCodeLine{  addBanner: true}
\DoxyCodeLine{\}); }

\end{DoxyCode}



\begin{DoxyItemize}
\item $\ast$$\ast${\ttfamily license\+Type\+Overrides}$\ast$$\ast$ -\/ override the license type for specific packages (default\+: disabled)
\end{DoxyItemize}

Example\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{new LicenseWebpackPlugin(\{}
\DoxyCodeLine{  licenseTypeOverrides: \{}
\DoxyCodeLine{    foopkg: 'MIT'}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\}); }

\end{DoxyCode}



\begin{DoxyItemize}
\item $\ast$$\ast${\ttfamily license\+Text\+Overrides}$\ast$$\ast$ -\/ override the license text for specific packages (default\+: disabled)
\end{DoxyItemize}

Example\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{new LicenseWebpackPlugin(\{}
\DoxyCodeLine{  licenseTextOverrides: \{}
\DoxyCodeLine{    foopkg: 'License text for foopkg'}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\}); }

\end{DoxyCode}



\begin{DoxyItemize}
\item $\ast$$\ast${\ttfamily license\+File\+Overrides}$\ast$$\ast$ -\/ override the license filename for specific packages (default\+: disabled)
\end{DoxyItemize}

Example\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{new LicenseWebpackPlugin(\{}
\DoxyCodeLine{  licenseFileOverrides: \{}
\DoxyCodeLine{    foopkg: 'The-\/License.txt'}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\}); }

\end{DoxyCode}


Notes\+: The license filename is resolved relative to the package directory.


\begin{DoxyItemize}
\item $\ast$$\ast${\ttfamily render\+Licenses}$\ast$$\ast$ -\/ change the format / contents of the generated license file (default\+: print package name, license type, and license text)
\end{DoxyItemize}

Example\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{new LicenseWebpackPlugin(\{}
\DoxyCodeLine{  renderLicenses: (modules) => \{}
\DoxyCodeLine{    console.log(modules[0].packageJson, modules[0].licenseId, modules[0].licenseText);}
\DoxyCodeLine{    return JSON.stringify(modules);}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\}); }

\end{DoxyCode}



\begin{DoxyItemize}
\item $\ast$$\ast${\ttfamily render\+Banner}$\ast$$\ast$ -\/ change the format / contents of the banner written to the top of each js file (default\+: print message indicating license filename)
\end{DoxyItemize}

Example\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{new LicenseWebpackPlugin(\{}
\DoxyCodeLine{  addBanner: true, }
\DoxyCodeLine{  renderBanner: (filename, modules) => \{}
\DoxyCodeLine{    console.log(modules);}
\DoxyCodeLine{    return '/*! licenses are at ' + filename + '*/';}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\}); }

\end{DoxyCode}



\begin{DoxyItemize}
\item $\ast$$\ast${\ttfamily handle\+Missing\+License\+Text}$\ast$$\ast$ -\/ do something when license text is missing from a package (default\+: disabled)
\end{DoxyItemize}

Example\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{new LicenseWebpackPlugin(\{}
\DoxyCodeLine{  handleMissingLicenseText: (packageName, licenseType) => \{}
\DoxyCodeLine{    console.log('Cannot find license for ' + packageName);}
\DoxyCodeLine{    return 'UNKNOWN';}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\}); }

\end{DoxyCode}


Notes\+: You can return your own license text from this function, but you should prefer using {\ttfamily license\+Text\+Overrides} first.


\begin{DoxyItemize}
\item $\ast$$\ast${\ttfamily license\+Template\+Dir}$\ast$$\ast$ -\/ use fallback license files for when a package is missing a license file (default\+: disabled)
\end{DoxyItemize}

Example\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{new LicenseWebpackPlugin(\{}
\DoxyCodeLine{  licenseTemplateDir: path.resolve(\_\_dirname, 'licenseTemplates')}
\DoxyCodeLine{\}); }

\end{DoxyCode}


Notes\+: This option specifies a directory containing {\ttfamily .txt} files containing the license text based on the license type. (e.\+g. {\ttfamily MIT.\+txt}). Templates can be found \href{https://github.com/spdx/license-list}{\texttt{ here}}.


\begin{DoxyItemize}
\item $\ast$$\ast${\ttfamily chunk\+Include\+Exclude\+Test}$\ast$$\ast$ -\/ control which chunks gets processed by the plugin (default\+: all chunks get processed)
\end{DoxyItemize}

Example\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{new LicenseWebpackPlugin(\{}
\DoxyCodeLine{  chunkIncludeExcludeTest: \{}
\DoxyCodeLine{    exclude: ['foo'],}
\DoxyCodeLine{    include: ['bar']}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\}); }

\end{DoxyCode}


Example\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{new LicenseWebpackPlugin(\{}
\DoxyCodeLine{  chunkIncludeExcludeTest: (chunkName) => chunkName.startsWith('abc')}
\DoxyCodeLine{\}); }

\end{DoxyCode}


Notes\+: If there is a duplicate entry in both the {\ttfamily exclude} and {\ttfamily include} array, the duplicated entry will be excluded.


\begin{DoxyItemize}
\item $\ast$$\ast${\ttfamily modules\+Directories}$\ast$$\ast$ -\/ limit which directories get scanned for license files (default\+: disabled)
\end{DoxyItemize}

Example\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{new LicenseWebpackPlugin(\{}
\DoxyCodeLine{  modulesDirectories: [}
\DoxyCodeLine{    path.resolve(\_\_dirname, 'node\_modules')}
\DoxyCodeLine{  ]}
\DoxyCodeLine{\}); }

\end{DoxyCode}



\begin{DoxyItemize}
\item $\ast$$\ast${\ttfamily additional\+Chunk\+Modules}$\ast$$\ast$ -\/ add additional node modules to a chunk (default\+: disabled)
\end{DoxyItemize}

Example\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{new LicenseWebpackPlugin(\{}
\DoxyCodeLine{  additionalChunkModules: \{}
\DoxyCodeLine{    main: [}
\DoxyCodeLine{      \{}
\DoxyCodeLine{        name: 'somepkg'}
\DoxyCodeLine{        directory: path.join(\_\_dirname, 'node\_modules', 'somepkg')}
\DoxyCodeLine{      \}}
\DoxyCodeLine{    ]}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\}); }

\end{DoxyCode}



\begin{DoxyItemize}
\item $\ast$$\ast${\ttfamily additional\+Modules}$\ast$$\ast$ -\/ add additional node modules to the scan (default\+: disabled)
\end{DoxyItemize}

Example\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{new LicenseWebpackPlugin(\{}
\DoxyCodeLine{  additionalModules: [}
\DoxyCodeLine{    \{}
\DoxyCodeLine{      name: 'somepkg'}
\DoxyCodeLine{      directory: path.join(\_\_dirname, 'node\_modules', 'somepkg')}
\DoxyCodeLine{    \}}
\DoxyCodeLine{  ]}
\DoxyCodeLine{\}); }

\end{DoxyCode}



\begin{DoxyItemize}
\item $\ast$$\ast${\ttfamily preferred\+License\+Types}$\ast$$\ast$ -\/ help the plugin decide which license type to pick in case a package specifies multiple licenses (default\+: disabled)
\end{DoxyItemize}

Example\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{new LicenseWebpackPlugin(\{}
\DoxyCodeLine{  preferredLicenseTypes: ['MIT', 'ISC']}
\DoxyCodeLine{\}); }

\end{DoxyCode}



\begin{DoxyItemize}
\item $\ast$$\ast${\ttfamily handle\+License\+Ambiguity}$\ast$$\ast$ -\/ do something when the plugin finds ambiguous license types (default\+: pick first license type)
\end{DoxyItemize}

Example\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{new LicenseWebpackPlugin(\{}
\DoxyCodeLine{  handleLicenseAmbiguity: (packageName, licenses) => \{}
\DoxyCodeLine{    console.log(packageName);}
\DoxyCodeLine{    console.log(licenses[0].url);}
\DoxyCodeLine{    return licenses[0].type;}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\}); }

\end{DoxyCode}


Notes\+: This function is called whenever a license type could not be determined when a package uses the deprecated {\ttfamily licenses} field (which is an array of license types) in its package.\+json. It should return the license type to use. By default, the plugin prints a warning message to the console and chooses the first license type. You should use the {\ttfamily preferred\+License\+Types} option instead of this one.


\begin{DoxyItemize}
\item $\ast$$\ast${\ttfamily handle\+Missing\+License\+Type}$\ast$$\ast$ -\/ do something when a package is missing a license type (default\+: disabled)
\end{DoxyItemize}

Example\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{new LicenseWebpackPlugin(\{}
\DoxyCodeLine{  handleMissingLicenseType: (packageName) => \{}
\DoxyCodeLine{    console.log(packageName);}
\DoxyCodeLine{    return null;}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\}); }

\end{DoxyCode}


Notes\+: You can return a license type from this function, but it is a better idea to use the {\ttfamily license\+Type\+Overides} option.


\begin{DoxyItemize}
\item $\ast$$\ast${\ttfamily skip\+Child\+Compilers}$\ast$$\ast$ -\/ do not apply the plugin to child webpack compilers (default\+: applies to child compilers too)
\end{DoxyItemize}

Example\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{new LicenseWebpackPlugin(\{}
\DoxyCodeLine{  skipChildCompilers: true}
\DoxyCodeLine{\}); }

\end{DoxyCode}
 