forked from RexSkz/json-diff-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.ts
80 lines (75 loc) · 1.72 KB
/
rollup.config.ts
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
import commonjs from '@rollup/plugin-commonjs';
import esbuild from 'rollup-plugin-esbuild';
import html from '@rollup/plugin-html';
import less from 'rollup-plugin-less';
import livereload from 'rollup-plugin-livereload';
import resolve from '@rollup/plugin-node-resolve';
import serve from 'rollup-plugin-serve';
import styles from 'rollup-plugin-styles';
import packageJson from './package.json';
const BASEDIR = process.env.BASEDIR || '.cache';
const plugins = [
resolve({ preferBuiltins: true }),
commonjs(),
esbuild({
exclude: [],
minify: process.env.NODE_ENV === 'production',
jsxFactory: 'React.createElement',
jsxFragment: 'React.Fragment',
define: {
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
__VERSION__: JSON.stringify(packageJson.version),
},
loaders: {
'.json': 'json', // require @rollup/plugin-commonjs
'.js': 'jsx',
},
}),
less({
output: `${BASEDIR}/index.css`,
insert: true,
}),
styles(),
html({
template: ({ files }) => {
return `<!DOCTYPE html>
<html>
<head>
<title>JSON Diff Kit Playground</title>
</head>
<body>
<div id="root"></div>
${files.js.map(({ fileName }) => `<script src="${fileName}"></script>`)}
</body>
</html>
`;
},
}),
];
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',
},
},
plugins,
};