forked from leanprover/vscode-lean4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
104 lines (100 loc) · 3.12 KB
/
rollup.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import commonjs from '@rollup/plugin-commonjs'
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 typescript from '@rollup/plugin-typescript'
import url from '@rollup/plugin-url'
import css from 'rollup-plugin-css-only'
/** @type {import('rollup').OutputOptions} */
const output =
process.env.NODE_ENV && process.env.NODE_ENV === 'production'
? {
dir: 'dist',
sourcemap: false,
format: 'esm',
compact: true,
entryFileNames: '[name].production.min.js',
chunkFileNames: '[name]-[hash].production.min.js',
plugins: [terser()],
}
: {
dir: 'dist',
sourcemap: 'inline',
format: 'esm',
entryFileNames: '[name].development.js',
chunkFileNames: '[name]-[hash].development.js',
}
/** @type {import('rollup').InputPluginOption} */
const plugins = [
url({
include: ['**/*.ttf'],
fileName: '[name][extname]',
}),
typescript({
tsconfig: './tsconfig.json',
outputToFilesystem: false,
// https://stackoverflow.com/a/63235210
sourceMap: false,
}),
nodeResolve({
browser: true,
}),
replace({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
preventAssignment: true, // TODO delete when `true` becomes the default
}),
commonjs(),
json(),
]
/**
* Note that besides building the infoview single-page application, we build a loader and a bunch
* of esm-shims. This is a way of compiling our dependencies into single-file ES modules which can
* be shared as imports between the infoview app and dynamically loaded widget modules. Although
* projects such * as jspm.io do exist, they tend to chunk modules into a bunch of files which are
* not easy to * bundle, and requiring them dynamically would make the infoview depend on an internet
* connection. See also `README.md`.
*
* @type {import('rollup').RollupOptions[]}
*/
const configs = [
{
output,
plugins: plugins.concat([
css({
output: 'index.css',
}),
]),
input: 'src/index.tsx',
external: ['react', 'react-dom', 'react/jsx-runtime'],
},
{
output: {
...output,
// Put `es-module-shims` in shim mode, needed to support dynamic `import`s.
// This code has to be set before `es-module-shims` is loaded,
// so we put it in the Rollup intro.
intro: 'window.esmsInitOptions = { shimMode: true }',
},
plugins,
input: 'src/loader.ts',
},
{
output,
plugins,
input: 'src/esm-shims/react.ts',
},
{
output,
plugins,
input: 'src/esm-shims/react-dom.ts',
external: ['react'],
},
{
output,
plugins,
input: 'src/esm-shims/react-jsx-runtime.ts',
external: ['react'],
},
]
export default configs