-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.ts
66 lines (64 loc) · 1.66 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
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 resolve from '@rollup/plugin-node-resolve';
import { string } from 'rollup-plugin-string';
import serve from 'rollup-plugin-serve';
const BASEDIR = process.env.BASEDIR || '.cache';
export default {
input: 'demo/index.tsx',
output: {
file: `${BASEDIR}/index.js`,
format: 'umd',
name: 'ProtoMessageHelper',
globals: {
react: 'React',
'react-dom': 'ReactDOM',
},
},
plugins: [
string({ include: ['**/*.proto', '**/*.bin'] }),
resolve({ preferBuiltins: false }),
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(require('./package.json').version),
},
loaders: {
'.json': 'json', // require @rollup/plugin-commonjs
'.js': 'jsx',
},
}),
less({
output: `${BASEDIR}/index.css`,
}),
html({
template: ({ files }) => {
return `<!DOCTYPE html>
<html>
<head>
<title>Proto Message Helper Demo</title>
<link rel="stylesheet" href="index.css" />
</head>
<body>
<div id="root"></div>
${files.js.map(({ fileName }) => `<script src="${fileName}"></script>`)}
</body>
</html>
`;
},
}),
process.env.NODE_ENV !== 'production' && serve({
contentBase: BASEDIR,
open: true,
openPage: '/index.html',
port: 3000,
}),
],
};