Coder Social home page Coder Social logo

huyinghuan / license-webpack-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xz64/license-webpack-plugin

0.0 2.0 0.0 96 KB

Outputs licenses from 3rd party libraries to a file

License: ISC License

HTML 0.61% TypeScript 41.86% JavaScript 57.53%

license-webpack-plugin's Introduction

License Webpack Plugin

Build Status

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 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, // 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 combined
  outputTemplate: 'output.template.ejs'), // ejs template for rendering the licenses. The default one is contained in the license-webpack-plugin directory under node_modules
  outputFilename: '[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 messages
  includePackagesWithoutLicense: false, // whether or not to include packages that are missing a license
  unacceptablePattern: undefined, // regex of unacceptable licenses
  abortOnUnacceptableLicense: false, // whether or not to abort the build if an unacceptable license is detected
  addBanner: false, // whether or not to add a banner to the beginning of all js files in the chunk indicating where the licenses are
  bannerTemplate: // 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 produced
  excludedChunks: [], // 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 @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

license-webpack-plugin's People

Contributors

xz64 avatar cakeinpanic avatar dvdckl avatar filipesilva avatar

Watchers

James Cloos avatar L.T avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.