-
Notifications
You must be signed in to change notification settings - Fork 3
/
rollup.config.mjs
112 lines (104 loc) · 2.35 KB
/
rollup.config.mjs
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
107
108
109
110
111
112
import alias from '@rollup/plugin-alias';
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import copy from 'rollup-plugin-copy';
import json from '@rollup/plugin-json';
import resolve from '@rollup/plugin-node-resolve';
import replace from '@rollup/plugin-replace';
import {
readFileSync
} from 'fs';
const pkg = importPkg();
const nonbundledDependencies = Object.keys({ ...pkg.dependencies, ...pkg.peerDependencies });
const nonExternalDependencies = [ 'preact-markup' ];
export default [
{
input: 'src/index.js',
output: [
{
sourcemap: true,
format: 'commonjs',
file: pkg.main
},
{
sourcemap: true,
format: 'esm',
file: pkg.module
}
],
external: externalDependencies(),
plugins: pgl([
copy({
targets: [
{ src: 'assets/*.css', dest: 'dist/assets' }
]
})
])
},
{
input: 'src/core.js',
output: [
{
sourcemap: true,
format: 'commonjs',
file: 'dist/core.js'
},
{
sourcemap: true,
format: 'esm',
file: 'dist/core.esm.js'
}
],
external: externalDependencies(),
plugins: corePlugins()
}
];
function pgl(plugins = []) {
return corePlugins([
...plugins,
alias({
entries: [
{ find: 'react', replacement: '@bpmn-io/properties-panel/preact/compat' },
{ find: 'preact', replacement: '@bpmn-io/properties-panel/preact' }
]
}),
babel({
babelHelpers: 'bundled',
plugins: [
[ '@babel/plugin-transform-react-jsx', {
'importSource': '@bpmn-io/properties-panel/preact',
'runtime': 'automatic'
} ]
]
})
]);
}
function corePlugins(plugins = []) {
return [
...plugins,
replace({
preventAssignment: true,
values: {
'process.env.PKG_VERSION': JSON.stringify(pkg.version)
}
}),
json(),
resolve({
mainFields: [
'browser',
'module',
'main'
]
}),
commonjs()
];
}
function externalDependencies() {
return id => {
return nonbundledDependencies.find(dep => id.startsWith(dep)) &&
!nonExternalDependencies.find(dep => id.startsWith(dep));
};
}
function importPkg() {
return JSON.parse(readFileSync('./package.json', { encoding:'utf8' }));
}