UNPKG

5.42 kBTypeScriptView Raw
1import { Plugin, PluginContext, TransformPluginContext } from 'rollup';
2import { FilterPattern, CreateFilter } from '@rollup/pluginutils';
3import * as babelCore from '@babel/core';
4
5export interface RollupBabelInputPluginOptions
6 extends Omit<babelCore.TransformOptions, 'include' | 'exclude'> {
7 /**
8 * A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should operate on. When relying on Babel configuration files you cannot include files already excluded there.
9 * @default undefined;
10 */
11 include?: FilterPattern;
12 /**
13 * A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should ignore. When relaying on Babel configuration files you can only exclude additional files with this option, you cannot override what you have configured for Babel itself.
14 * @default undefined;
15 */
16 exclude?: FilterPattern;
17 /**
18 * Custom filter function can be used to determine whether or not certain modules should be operated upon.
19 * Example:
20 * import { createFilter } from '@rollup/pluginutils';
21 * const include = 'include/**.js';
22 * const exclude = 'exclude/**.js';
23 * const filter = createFilter(include, exclude, {});
24 * @default undefined;
25 */
26 filter?: ReturnType<CreateFilter>;
27 /**
28 * An array of file extensions that Babel should transpile. If you want to transpile TypeScript files with this plugin it's essential to include .ts and .tsx in this option.
29 * @default ['.js', '.jsx', '.es6', '.es', '.mjs']
30 */
31 extensions?: string[];
32 /**
33 * It is recommended to configure this option explicitly (even if with its default value) so an informed decision is taken on how those babel helpers are inserted into the code.
34 * @default 'bundled'
35 */
36 babelHelpers?: 'bundled' | 'runtime' | 'inline' | 'external';
37 /**
38 * Before transpiling your input files this plugin also transpile a short piece of code for each input file. This is used to validate some misconfiguration errors, but for sufficiently big projects it can slow your build times so if you are confident about your configuration then you might disable those checks with this option.
39 * @default false
40 */
41 skipPreflightCheck?: boolean;
42}
43
44export interface RollupBabelOutputPluginOptions
45 extends Omit<babelCore.TransformOptions, 'include' | 'exclude'> {
46 /**
47 * Use with other formats than UMD/IIFE.
48 * @default false
49 */
50 allowAllFormats?: boolean;
51}
52
53export type RollupBabelCustomInputPluginOptions = (
54 options: RollupBabelInputPluginOptions & Record<string, any>
55) => {
56 customOptions: Record<string, any>;
57 pluginOptions: RollupBabelInputPluginOptions;
58};
59export type RollupBabelCustomOutputPluginOptions = (
60 options: RollupBabelOutputPluginOptions & Record<string, any>
61) => {
62 customOptions: Record<string, any>;
63 pluginOptions: RollupBabelOutputPluginOptions;
64};
65export interface RollupBabelCustomPluginConfigOptions {
66 code: string;
67 customOptions: Record<string, any>;
68}
69export interface RollupBabelCustomPluginResultOptions {
70 code: string;
71 customOptions: Record<string, any>;
72 config: babelCore.PartialConfig;
73 transformOptions: babelCore.TransformOptions;
74}
75export type RollupBabelCustomInputPluginConfig = (
76 this: TransformPluginContext,
77 cfg: babelCore.PartialConfig,
78 options: RollupBabelCustomPluginConfigOptions
79) => babelCore.TransformOptions;
80export type RollupBabelCustomInputPluginResult = (
81 this: TransformPluginContext,
82 result: babelCore.BabelFileResult,
83 options: RollupBabelCustomPluginResultOptions
84) => babelCore.BabelFileResult;
85export type RollupBabelCustomOutputPluginConfig = (
86 this: PluginContext,
87 cfg: babelCore.PartialConfig,
88 options: RollupBabelCustomPluginConfigOptions
89) => babelCore.TransformOptions;
90export type RollupBabelCustomOutputPluginResult = (
91 this: PluginContext,
92 result: babelCore.BabelFileResult,
93 options: RollupBabelCustomPluginResultOptions
94) => babelCore.BabelFileResult;
95export interface RollupBabelCustomInputPlugin {
96 options?: RollupBabelCustomInputPluginOptions;
97 config?: RollupBabelCustomInputPluginConfig;
98 result?: RollupBabelCustomInputPluginResult;
99}
100export interface RollupBabelCustomOutputPlugin {
101 options?: RollupBabelCustomOutputPluginOptions;
102 config?: RollupBabelCustomOutputPluginConfig;
103 result?: RollupBabelCustomOutputPluginResult;
104}
105export type RollupBabelCustomInputPluginBuilder = (
106 babel: typeof babelCore
107) => RollupBabelCustomInputPlugin;
108export type RollupBabelCustomOutputPluginBuilder = (
109 babel: typeof babelCore
110) => RollupBabelCustomOutputPlugin;
111
112/**
113 * A Rollup plugin for seamless integration between Rollup and Babel.
114 * @param options - Plugin options.
115 * @returns Plugin instance.
116 */
117export function getBabelInputPlugin(options?: RollupBabelInputPluginOptions): Plugin;
118export function getBabelOutputPlugin(options?: RollupBabelOutputPluginOptions): Plugin;
119
120export function createBabelInputPluginFactory(
121 customCallback?: RollupBabelCustomInputPluginBuilder
122): typeof getBabelInputPlugin;
123export function createBabelOutputPluginFactory(
124 customCallback?: RollupBabelCustomOutputPluginBuilder
125): typeof getBabelOutputPlugin;
126
127/**
128 * A Rollup plugin for seamless integration between Rollup and Babel.
129 * @param options - Plugin options.
130 * @returns Plugin instance.
131 */
132export function babel(options?: RollupBabelInputPluginOptions): Plugin;
133export default babel;