forked from canvg/canvg
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollup.config.js
106 lines (104 loc) · 2.13 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import eslint from '@rollup/plugin-eslint';
import commonjs from '@rollup/plugin-commonjs';
import globals from 'rollup-plugin-node-globals';
import typescript from 'rollup-plugin-typescript2';
import replace from '@rollup/plugin-replace';
import babel from '@rollup/plugin-babel';
import resolve from '@rollup/plugin-node-resolve';
import {
terser
} from 'rollup-plugin-terser';
import {
DEFAULT_EXTENSIONS
} from '@babel/core';
import {
external
} from './scripts/rollup-helpers';
import pkg from './package.json';
function getPlugins({
standalone = false,
transpile = true,
esmodules = false
} = {}) {
return [
eslint({
exclude: ['**/*.json', 'node_modules/**'],
throwOnError: true
}),
commonjs(),
standalone && globals(),
typescript(),
replace({
'process.env.NODE_ENV': JSON.stringify(
process.env.ROLLUP_WATCH
? 'development'
: 'production'
)
}),
transpile && babel({
extensions: [
...DEFAULT_EXTENSIONS,
'ts',
'tsx'
],
babelHelpers: 'runtime',
// erring otherwise in attempt to find `@babel/plugin-transform-runtime`
// added by `@trigen/babel-preset`; see
// https://github.com/rollup/plugins/issues/381
skipPreflightCheck: true,
...esmodules ? {
babelrc: false,
configFile: './.babelrc.esmodules.json'
} : {}
}),
standalone && resolve({
preferBuiltins: false
}),
!process.env.ROLLUP_WATCH && standalone && terser()
].filter(Boolean);
}
export default [{
input: 'src/index.ts',
plugins: getPlugins(),
external: external(pkg, true),
output: {
file: pkg.main,
format: 'cjs',
exports: 'named',
sourcemap: 'inline'
}
}, {
input: 'src/index.ts',
plugins: getPlugins({
esmodules: true
}),
external: external(pkg, true),
output: {
file: pkg.module,
format: 'es',
sourcemap: 'inline'
}
}, {
input: 'src/index.ts',
plugins: getPlugins({
transpile: false
}),
external: external(pkg, true),
output: {
file: pkg.raw,
format: 'es',
sourcemap: 'inline'
}
}, {
input: 'src/index.ts',
plugins: getPlugins({
standalone: true
}),
output: {
file: pkg.umd,
format: 'umd',
exports: 'named',
name: 'canvg',
sourcemap: true
}
}];