@azimutlabs/rollup-config
v1.0.1
Published
Compose, combine, merge and create Rollup configurations
Downloads
12
Readme
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.