-
Notifications
You must be signed in to change notification settings - Fork 198
/
rollup-boot.config.js
73 lines (61 loc) · 2.16 KB
/
rollup-boot.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
import { babel } from '@rollup/plugin-babel';
import json from '@rollup/plugin-json';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import replace from '@rollup/plugin-replace';
import terser from '@rollup/plugin-terser';
import { readFileSync } from 'fs';
const isProd = process.env.NODE_ENV === 'production';
const prodPlugins = [];
if (isProd) {
prodPlugins.push(terser());
}
const { version } = JSON.parse(readFileSync('./package.json').toString());
// URL template which is expanded by the boot script. See `src/boot/url-template.js`.
const localhost = '{current_scheme}://{current_host}';
const notebookAppUrl = process.env.NOTEBOOK_APP_URL
? `${process.env.NOTEBOOK_APP_URL}`
: `${localhost}:5000/notebook`;
const profileAppUrl = process.env.PROFILE_APP_URL
? `${process.env.PROFILE_APP_URL}`
: `${localhost}:5000/user-profile`;
const sidebarAppUrl = process.env.SIDEBAR_APP_URL
? `${process.env.SIDEBAR_APP_URL}`
: `${localhost}:5000/app.html`;
// nb. Replace `isProd` with `false` here to test a production build of the client
// served locally.
const assetRoot = isProd
? `https://cdn.hypothes.is/hypothesis/${version}/`
: `${localhost}:3001/hypothesis/${version}/`;
export default {
input: 'src/boot/index.ts',
output: {
file: 'build/boot.js',
// Built as an IIFE rather than ES module because there are many existing
// <script> tags on websites that load it as a non-module script.
format: 'iife',
sourcemap: false,
},
preserveEntrySignatures: false,
treeshake: isProd,
plugins: [
replace({
preventAssignment: true,
values: {
__ASSET_ROOT__: assetRoot,
__NOTEBOOK_APP_URL__: notebookAppUrl,
__PROFILE_APP_URL__: profileAppUrl,
__SIDEBAR_APP_URL__: sidebarAppUrl,
},
}),
babel({
// Rollup docs recommend against "inline", but for this tiny bundle it
// produces a prod bundle of the same size and dev bundle that has less cruft in it.
babelHelpers: 'inline',
exclude: 'node_modules/**',
extensions: ['.js', '.ts', '.tsx'],
}),
json(),
nodeResolve({ extensions: ['.js', '.ts', '.tsx'] }),
...prodPlugins,
],
};