GithubHelp home page GithubHelp logo

ruthatd / videojs-generate-rollup-config Goto Github PK

View Code? Open in Web Editor NEW

This project forked from videojs/videojs-generate-rollup-config

0.0 0.0 0.0 1 MB

Generate a standard rollup config, so that plugins don't need the same script in every repository.

License: Other

JavaScript 100.00%

videojs-generate-rollup-config's Introduction

videojs-generate-rollup-config

Build Status Greenkeeper badge Slack Status

NPM

Currently rollup configs are the same for most plugins, but when the default config changes a bit, every repository has to be updated since it is a static file. This package will provide the standard config as a module, so that updates can be deployed much easier.

Lead Maintainer: Brandon Casey @brandonocasey

Maintenance Status: Stable

Table of Contents

Installation

Note: version 3+ support rollup ^1.0.0. If you need older rollup support please use version 2.

$ npm install --save-dev rollup videojs-generate-rollup-config

Then in your rollup config do

const generateRollupConfig = require('videojs-generate-rollup-config');
const config = generateRollupConfig();

/**
 * Now you have:
 * - config.settings: An object containing the settings used to generate the builds.
 * - config.builds: An object containing the generated builds, with the name of the build as the key:
 *   - cjs
 *   - es
 *   - test
 *   - browser
 *   - minBrowser, this will be excluded by default in watch mode. See the `checkWatch` option.
 */

// Note that you have to take the values from config.builds, since rollup takes an array.
export default Object.values(config.builds);

Before you exports you can customize the builds, and you can also pass options (outlined below) to customize the builds.

Environment variables

These can be passed via rollup's --environment or just setting an environment variable

TEST_BUNDLE_ONLY

Type: Boolean Default: false

Set this to any JavaScript truthy value, to only create a test build target. If this option is present NO_TEST_BUNDLE will be ignored.

NO_TEST_BUNDLE

Type: Boolean Default: false

Set this to any JavaScript truthy value, to create all build targets except test. This option will be ignored if TEST_BUNDLE_ONLY is set.

Function Options

options that are passed as an object to the generateRollupConfig function.

input

Type: string Default: src/plugin.js

The entry point for your build.

minifierPlugin

Type: string Default: uglify

The name of the primed plugin to use when minifying

testInput

Type: string Default: test/**/*.test.js

The entry point for tests.

distName

Type: string Default: Your package name minus scope.

Determines the dist file names for your build. IE: @thing/videojs-foo-bar would have a distName of videojs-foo-bar and build to dist/videojs-foo-var.js etc.

exportName

Type: string Default: Your package name minus scope in camel case.

Determines the export name for browser and test dist files of your build. IE:

  • @thing/videojs-foo-bar would have a exportName of videojsFooBar.
  • The browser/minBrowser dist would be exported to window as window.videojsFooBar.
  • The test dist would be exported to window as window.videojsFooBarTests.

excludeCoverage

Type: Function Default: no default

A callback to change the files that are excluded from test coverage.

This function takes one argument and will be passed the default files that are excluded from coverage, see below. This function must return the final list of files that should be excluded from coverage.

Defaults are as follows:

NOTE: __dirname refers to the directory of videojs-generate-rollup-config. This is used because some rollup plugins insert special transforms.

['test/**', path.join(__dirname, '**'), 'node_modules/**', 'package.json']

coverage

Type: Boolean Default: true

Whether to include istanbul for the unit test bundle. By default it is included.

browserslist

Type: string|Array Default: ['defaults', 'ie 11']

What browser syntax should be supported in the browser/test dist files. Can also be specified in the package.json as a top level browserslist key/value. See the browserslist repo for more information.

checkWatch

Type: boolean Default: true

Determines if we should check if rollup is in watch mode. If it is we exclude the minBrowser build to save development time.

banner

Type: string Default: /*! @name ${pkg.name} @version ${pkg.version} @license ${pkg.license} */

The banner that should be inserted to the top of all bundles. You probably should not change this from the default!

babel

Type: Function Default: no default

A callback to change the default settings for rollup-plugin-babel.

This function takes one argument, the default babel config. This function must return the final babel config that should be used for rollup-plugin-babel.

default babel config:

{
  babelrc: false,
  exclude: path.join(process.cwd(), 'node_modules/**'),
  presets: [
    [presetEnv, {loose: true, modules: false, targets: {browsers: settings.browserslist}}]
  ],
  plugins: [
    transformObjectAssign
  ]
};

Example:

const config = generateRollupConfig({
  babel(default) {
    default.plugins.push('babel-plugin-lodash');

    return default;
  }
})

globals

Type: Function Default: no default

A callback to change the build globals for the rollup build before they are used.

This function takes one argument and will be passed the defaultGlobals. This function must return the final globals that should be used to create the rollup build list.

Example:

const config = generateRollupConfig({
  globals(defaults) {
    return {
      browser: Object.assign(defaults.browser, {
        'foo-bar': 'foo',
      }),
      module: Object.assign(defaults.module, {
        'foo-bar': 'foo'
      }),
      test: Object.assign(defaults.test, {
        'foo-bar': 'foo'
      }),
    };
  }
})
};

externals

Type: Function Default: no default

A callback to change the build externals for the rollup build before they are used.

This function takes one argument and will be passed the defaultExternals. This function must return the final externals that should be used to create the rollup build list.

NOTE: You do not have to re-list globals in this list, all globals will be added as external automatically!

Example:

const config = generateRollupConfig({
  externals(defaults) {
    return {
      browser: defaults.browser.concat([
        'foo',
      ]),
      module: defaults.module.concat([
        'foo'
      ],
      test: defaults.test.concat([
        'foo'
      ],
    };
  }
});

plugins

Type: Function Default: no default

A callback to change the build plugins and plugin order for the rollup build before they are used.

This function takes one argument and will be passed the defaultPlugins. This function must return the final plugins that should be used to create the rollup build list.

NOTE: Plugins can be "primed", here or in the primedPlugins option. By default all plugins are primed later and referenced by their key in primedPlugins.

Example:

const config = generateRollupConfig({
  plugins(defaults) {
    return {
      browser: defaults.browser.concat([
        'foo',
      ]),
      module: defaults.module.concat([
        'foo'
      ],
      test: defaults.test.concat([
        'foo'
      ],
    };
  }
});

primedPlugins

Type: Function Default: no default

A callback to change the primed plugins for the rollup build before they are used.

This function takes one argument and will be passed the defaultPrimedPlugins. This function must return the final primed plugins that should be used to create the rollup build list.

Example:

const fooPlugin = require('rollup-plugin-foo');
const config = generateRollupConfig({
  primedPlugins(defaults) {
    return Object.assign(defaults, {
      foo: fooPlugin();
    });
  }
});

Defaults

defaultGlobals

An object that contains keys for browser, module, and test globals that will be used by default. See the code for the more info.

const defaultGlobals = {
  browser: {
    'video.js': 'videojs',
    'global': 'window',
    'global/window': 'window',
    'global/document': 'document'
  },
  module: {
    'video.js': 'videojs'
  },
  test: {
    'qunit': 'QUnit',
    'qunitjs': 'QUnit',
    'sinon': 'sinon',
    'video.js': 'videojs'
  }
};

defaultExternals

An object that contains keys for browser, module, and test externals that will be used by default.

NOTE: that we automatically add on any of globals provided into this list, as that is the default rollup behavior.

const defaultExternals = {
  browser: [],
  module: [
    'global',
    'global/document',
    'global/window'
  ],
  test: []
};

defaultPlugins

An object that contains keys for browser, module, and test plugins that will be used by default.

NOTE: The plugins are referenced as strings that will be the keys in the primedPlugins that generateRollupConfig uses.

const defaultPlugins = {
  // note that for the minBrowser build uglify will be inserted before
  // babel.
  browser: [
    'resolve',
    'json',
    'commonjs',
    'babel'
  ],

  module: [
    'resolve',
    'json',
    'commonjs',
    'babel'
  ],

  test: [
    'multiEntry',
    'resolve',
    'json',
    'commonjs',
    'babel'
  ]
};

defaultPrimedPlugins

An object that contains primed rollup plugins

const defaultPrimedPlugins = {
  babel: babel({
    babelrc: false,
    exclude: 'node_modules/**',
    presets: [
      [presetEnv, {loose: true, modules: false, targets: {browsers: settings.browserslist}}]
    ],
    plugins: [
      externalHelpers,
      transformObjectAssign
    ]
  }),
  commonjs: commonjs({sourceMap: false}),
  json: json(),
  multiEntry: multiEntry({exports: false}),
  resolve: resolve({browser: true, main: true, jsnext: true}),
  uglify: uglify({output: {comments: 'some'}}, minify)
};

videojs-generate-rollup-config's People

Contributors

brandonocasey avatar gkatsev avatar misteroneill avatar alex-barstow avatar dzianis-dashkevich 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.