-
Notifications
You must be signed in to change notification settings - Fork 183
/
rollup.config.js
53 lines (49 loc) · 1.83 KB
/
rollup.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import terser from '@rollup/plugin-terser';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import babel from '@rollup/plugin-babel';
export const plugins = [resolve(), commonjs(), babel({ babelHelpers: 'bundled' })];
// For interfaces in their dedicated packages
export function linkifyInterface(name, opts = {}) {
const iifeOpts = { name };
const globals = { linkifyjs: 'linkify' };
const external = ['linkifyjs'];
if ('globalName' in opts) {
iifeOpts.name = opts.globalName;
}
if ('globals' in opts) {
Object.assign(globals, opts.globals);
}
if ('external' in opts) {
external.push(...opts.external);
}
return {
input: `src/linkify-${name}.js`,
external,
output: [
{ file: `dist/linkify-${name}.js`, format: 'iife', globals, ...iifeOpts },
{ file: `dist/linkify-${name}.min.js`, format: 'iife', globals, ...iifeOpts, plugins: [terser()] },
{ file: `dist/linkify-${name}.cjs.js`, format: 'cjs', exports: 'auto' },
{ file: `dist/linkify-${name}.es.js`, format: 'es' },
],
plugins,
};
}
// Includes plugins from main linkifyjs package because those have not yet been
// fully migrated to their own packages to maintain backward compatibility with
// v2. Will change in v4
export function linkifyPlugin(plugin, opts = {}) {
const name = opts.globalName || false; // Most plugins don't export anything
const globals = { linkifyjs: 'linkify' };
return {
input: 'src/index.js',
external: ['linkifyjs'],
output: [
{ file: `dist/linkify-plugin-${plugin}.js`, format: 'iife', globals, name },
{ file: `dist/linkify-plugin-${plugin}.min.js`, format: 'iife', globals, name, plugins: [terser()] },
{ file: `dist/linkify-plugin-${plugin}.cjs.js`, format: 'cjs', exports: 'auto' },
{ file: `dist/linkify-plugin-${plugin}.es.js`, format: 'es' },
],
plugins,
};
}