Coder Social home page Coder Social logo

brettz9 / rollup-plugin-license Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mjeanroy/rollup-plugin-license

0.0 3.0 0.0 303 KB

Rollup plugin to add license banner to the final bundle and output third party licenses

License: MIT License

JavaScript 100.00%

rollup-plugin-license's Introduction

rollup-plugin-license

Greenkeeper badge Build Status Npm version

Rollup plugin that can be used to:

  • Prepend a banner from a file.
  • Create a file containing all third-parties used in the bundle (and display the license of each dependency).

How to use

Install the plugin with NPM:

npm install --save-dev rollup-plugin-license

Then add it to your rollup configuration:

const path = require('path');
const license = require('rollup-plugin-license');

module.exports = {
  plugins: [
    license({
      sourceMap: true,
      cwd: '.', // Default is process.cwd()

      banner: {
        file: path.join(__dirname, 'LICENSE'),
        encoding: 'utf-8', // Default is utf-8

        // Optional, may be an object or a function returning an object.
        data() {
          return {
            foo: 'foo',
          };
        },
      },

      thirdParty: {
        output: path.join(__dirname, 'dist', 'dependencies.txt'),
        includePrivate: true, // Default is false.
        encoding: 'utf-8', // Default is utf-8.
      },
    }),
  ],
}

Since version 0.3.0, banner can be a simple string that will be used directly:

const path = require('path');
const license = require('rollup-plugin-license');

module.exports = {
  plugins: [
    license({
      banner: `Copyright <%= moment().format('YYYY') %>`,
    }),
  ],
}

Banner file

The banner file can be a text file and it will be converted to a block comment automatically if needed.

Note that the content will be translated to a lodash template with the following data model:

  • pkg: The content of the project package.json.
  • dependencies: An array of all the dependencies included in the bundle.
  • moment: The moment object.
  • _: The lodash object.
  • data A custom data object, defined in banner options.

Here is a valid banner:

Bundle of <%= pkg.name %>
Generated: <%= moment().format('YYYY-MM-DD') %>
Version: <%= pkg.version %>
Dependencies:
<% _.forEach(dependencies, function (dependency) { %>
  <%= dependency.name %> -- <%= dependency.version %>
<% }) %>

Dependencies output

A file containing a summary of all dependencies can be generated automatically using the following options:

license({
  thirdParty: {
    output: path.join(__dirname, 'dist', 'dependencies.txt'),
    includePrivate: true, // Default is false.
  },
})

Changelogs

  • 0.6.0
    • Add cwd option to specify custom working directory (optional option).
    • Add a way to specify custom data object when rendering banner.
    • Upgrade dependencies.
  • 0.5.0
    • Feat: Sourcemap is now enable by default to ensure compatibility with other rollup plugins.
    • Fix: Add compatibility with rollup >= 0.48.0 (the new sourcemap option).
    • Fix: Ensure plugin sourcemp is used instead of the "global" one in rollup options.
    • Chore: dependency updates.
  • 0.4.0
    • Dependency update (moment).
    • Dependency update (magic-string).
  • 0.3.0
    • Add encoding option for banner and third-party output file.
    • Banner can be a simple string.

License

MIT License (MIT)

Contributing

If you find a bug or think about enhancement, feel free to contribute and submit an issue or a pull request.

rollup-plugin-license's People

Contributors

mjeanroy avatar greenkeeper[bot] avatar gregod avatar

Watchers

Brett Zamir avatar James Cloos avatar  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.