-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrollup.config.ts
More file actions
55 lines (51 loc) · 1.29 KB
/
rollup.config.ts
File metadata and controls
55 lines (51 loc) · 1.29 KB
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
import fs from 'node:fs';
import type { RollupOptions } from 'rollup';
import { babel } from '@rollup/plugin-babel';
import nodeResolve from '@rollup/plugin-node-resolve';
// read content of "demo/demo.js"
const demoSourceRaw = fs.readFileSync('demo/demo.js', 'utf-8');
// Custom plugin to inject demoSourceRaw into index.base.html
function injectDemoSource() {
return {
name: 'inject-demo-source',
generateBundle() {
const htmlPath = 'demo/index.base.html';
const outPath = 'demo/index.html';
let html = fs.readFileSync(htmlPath, 'utf-8');
html = html.replace(
'{{demoSource}}',
demoSourceRaw.replace(
/[&<>]/g,
(c) => ({ '&': '&', '<': '<', '>': '>' }[c])
)
);
fs.writeFileSync(outPath, html);
},
};
}
const config: Array<RollupOptions> = [
{
input: 'src/index.ts',
output: {
dir: 'dist',
format: 'es',
},
plugins: [
babel({
babelHelpers: 'bundled',
extensions: ['.js', '.ts'],
exclude: 'node_modules/**',
}),
],
},
{
input: 'demo/demo.js',
output: {
file: 'demo/demo-bundle.js',
format: 'es',
name: 'ImmutableDevToolsDemo',
},
plugins: [nodeResolve(), injectDemoSource()],
},
];
export default config;