@azimutlabs/rollup-config
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

🍣 azimutlabs logo /rollup-config

Compose, combine, merge and create Rollup configurations

azimutlabs/rollup repository github workflow status azimutlabs/rollup repository license @azimutlabs/rollup-config

Installation

$ yarn add -D @azimutlabs/rollup-config

Usage

combine

Combine several configurations into a single RollupOptions object.

function combine(
  finalizers: ReadonlyArray<RollupConfig['finalize']>,
  format?: InternalModuleFormat,
  options?: RollupOptions
): RollupConfigFinalize;

Given example:

// rollup.config.js
import { combine } from '@azimutlabs/rollup-config';
import babel from '@azimutlabs/rollup-config-babel';
import typescript from '@azimutlabs/rollup-config-typescript';
// Order is important, because 'combine' will prefer to add the latest plugins in case of
// plugin merge conflicts.
export default combine([babel, typescript]);

...will result in:

// rollup.config.js
export default {
  /* ...merged RollupOptions */
  plugins: [
    // Babel from 'rollup-config-babel'.
    { name: 'babel' },
    // External and Node-Resolve here because of how 'combine' handles duplicate plugins.
    // It will prefer the latest plugins and keep them, stripping down the others.
    { name: 'external' },
    { name: 'node-resolve' },
    // TypeScript from 'rollup-config-typescript'.
    { name: 'typescript' },
  ],
}

compose

Compose multiple configurations into a singular array of RollupOptions.

function compose(...configs: ComposeFinalize[]): RollupConfigFinalize;

Just by using RollupConfigFinalize:

// rollup.config.js
import compose from '@azimutlabs/rollup-config';
import babel from '@azimutlabs/rollup-config-babel';
import typescript from '@azimutlabs/rollup-config-typescript';

export default compose(typescript('es'), babel('cjs'));

...will result in:

// lib/
//   index.d.ts - output from typescript
//   index.es.js - output from typescript
//   index.cjs.js - output from babel
export default [
  { /* typescript config */ },
  { /* babel config */ },
];

But if we use ComposeFinalizeWithEnv:

// rollup.config.js
import compose, { Envs } from '@azimutlabs/rollup-config';
import babel from '@azimutlabs/rollup-config-babel';
import typescript from '@azimutlabs/rollup-config-typescript';

export default compose(
  babel('cjs'),
  /**
   * You can even pass down multiple envs:
   * @example
   * [typescript('es'), [Envs.Test, Envs.Prod]]
   */
  [typescript('es'), Envs.Prod]
);

...final result will differ depending on NODE_ENV environment variable. By default, if no value provided, we will consider it as development:

// NODE_ENV === ''
// lib/
//   index.cjs.js - output from babel
export default [
  { /* babel config */ },
];
// NODE_ENV === 'production'
// lib/
//   index.d.ts - output from typescript
//   index.es.js - output from typescript
//   index.cjs.js - output from babel
export default [
  { /* babel config */ },
  { /* typescript config */ },
];

RollupConfig

Class used as the base of our configurations. Consider checking contributing to learn more about it.

Contributing

Any PR is welcomed by our @js-opensource team. Check out our contributing guidelines for more info.

License

azimutlabs rollup config license

Package Sidebar

Install

npm i @azimutlabs/rollup-config

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

39.1 kB

Total Files

46

Last publish

Collaborators

  • azimutlabs-owner
  • olehan