-
Notifications
You must be signed in to change notification settings - Fork 12
/
rollup.config.pages.mjs
91 lines (86 loc) · 2.15 KB
/
rollup.config.pages.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
import commonjs from '@rollup/plugin-commonjs';
import html from '@rollup/plugin-html';
import less from 'rollup-plugin-less';
import livereload from 'rollup-plugin-livereload';
import replace from '@rollup/plugin-replace';
import resolve from '@rollup/plugin-node-resolve';
import serve from 'rollup-plugin-serve';
import styles from 'rollup-plugin-styles';
import swc from '@rollup/plugin-swc';
import packageJson from './package.json' assert { type: 'json' };
const BASEDIR = process.env.BASEDIR || '.cache';
const plugins = [
less({
output: `${BASEDIR}/index.css`,
insert: true,
}),
styles(),
html({
template: options => {
return `<!DOCTYPE html>
<html>
<head>
<title>JSON Diff Kit Playground</title>
<meta charset="utf-8" />
<script async src="https://www.googletagmanager.com/gtag/js?id=G-5D3V5T84WY"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-5D3V5T84WY');
</script>
<link rel="stylesheet" href="index.css" />
</head>
<body>
<div id="root"></div>
${options?.files.js.map(({ fileName }) => `<script src="${fileName}"></script>`)}
</body>
</html>
`;
},
}),
resolve({
preferBuiltins: true,
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'],
}),
commonjs(),
replace({
values: {
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
__VERSION__: JSON.stringify(packageJson.version),
},
preventAssignment: true,
}),
swc({
minify: process.env.NODE_ENV === 'production',
sourceMaps: process.env.NODE_ENV !== 'production',
}),
];
if (process.env.NODE_ENV !== 'production') {
plugins.push(
serve({
contentBase: BASEDIR,
open: true,
openPage: '/index.html',
port: 3000,
}),
livereload({
watch: BASEDIR,
delay: 300,
}),
);
}
export default {
input: 'playground/index.tsx',
output: {
file: `${BASEDIR}/index.js`,
format: 'umd',
name: 'JSONDiffKit',
globals: {
react: 'React',
'react-dom': 'ReactDOM',
},
sourcemap: process.env.NODE_ENV !== 'production',
},
plugins,
};