forked from eclipsesource/jsonforms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.example.config.js
87 lines (81 loc) · 2.32 KB
/
rollup.example.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
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import nodeResolve from '@rollup/plugin-node-resolve';
import replace from '@rollup/plugin-replace';
import copy from 'rollup-plugin-copy';
import css from 'rollup-plugin-import-css';
import typescript from 'rollup-plugin-typescript2';
// This little plugin mitigates Rollup's lack of support for pre-built CommonJS dependencies with
// default exports.
// For mor details see here: https://github.com/eclipsesource/jsonforms/pull/2139
function cjsCompatPlugin() {
return {
name: 'cjs-compat-plugin',
transform(code, id) {
// ignore all packages which are not @mui/utils
if (
!/@mui\/utils.*.js$/.test(id) ||
id.includes('@mui/utils/node_modules')
) {
return code;
}
// try to extract the commonjs namespace variable
const moduleName = code.match(
/(?<module>[a-zA-Z0-9_$]*).default = _default;/
)?.groups?.module;
if (!moduleName || !code.includes(`return ${moduleName};`)) {
return code;
}
// return default export instead of namespace
return code.replace(
`return ${moduleName}`,
`return ${moduleName}.default`
);
},
};
}
/**
* @type {import('rollup').RollupOptions}
*/
const config = {
input: 'example/index.ts',
output: {
file: 'example/dist/bundle.js',
format: 'iife',
sourcemap: true,
},
plugins: [
replace({
'process.env.NODE_ENV': JSON.stringify('production'),
preventAssignment: true, // recommended to be set by library to be forward compatible
}),
nodeResolve({ browser: true }),
// Transform mixed because some JsonForms modules use import and require
commonjs({ transformMixedEsModules: true }),
css(),
json(),
typescript({
tsconfigOverride: {
compilerOptions: {
// Do not emit typescript declarations for our bundled example app
declaration: false,
},
},
}),
cjsCompatPlugin(),
copy({
targets: [
{
src: 'example/index.bundled.html',
dest: 'example/dist',
rename: () => 'index.html',
},
{
src: '../examples-react/src/logo.svg',
dest: 'example/dist/assets',
},
],
}),
],
};
export default config;