forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.js
More file actions
199 lines (188 loc) · 5.45 KB
/
rollup.config.js
File metadata and controls
199 lines (188 loc) · 5.45 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
//! Licensed to the .NET Foundation under one or more agreements.
//! The .NET Foundation licenses this file to you under the MIT license.
import { defineConfig } from "rollup";
import typescript from "@rollup/plugin-typescript";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import dts from "rollup-plugin-dts";
import {
externalDependencies, envConstants, banner, banner_dts,
isDebug, staticLibDestination,
keep_classnames, keep_fnames, reserved
} from "./rollup.config.defines.js";
import { terserPlugin, writeOnChangePlugin, consts, onwarn, alwaysLF, iife2fe, sourcemapPathTransform } from "./rollup.config.plugins.js";
import { promises as fs } from "fs";
const dotnetDTS = {
input: "./libs/Common/JavaScript/types/export-api.ts",
output: [
{
format: "es",
file: staticLibDestination + "/dotnet.d.ts",
banner: banner_dts,
plugins: [writeOnChangePlugin()],
},
...(isDebug ? [{
format: "es",
file: "./corehost/browserhost/loader/dotnet.d.ts",
banner: banner_dts,
plugins: [alwaysLF(), writeOnChangePlugin()],
}] : [])
],
external: externalDependencies,
plugins: [dts()],
onwarn
};
const dotnetJS = configure({
input: "./corehost/browserhost/loader/dotnet.ts",
output: [{
file: staticLibDestination + "/dotnet.js",
intro: "/*! bundlerFriendlyImports */",
}],
terser: {
compress: {
module: true,
}, mangle: {
module: true,
}
}
});
const libNativeBrowser = configure({
input: "./libs/System.Native.Browser/native/index.ts",
output: [{
name: "libNativeBrowser",
format: "iife",
file: staticLibDestination + "/libSystem.Native.Browser.js",
footer: await fs.readFile("./libs/System.Native.Browser/libSystem.Native.Browser.footer.js"),
}],
terser: {
compress: {
toplevel: true,
keep_fnames,
}, mangle: {
toplevel: true,
keep_fnames,
reserved,
}
}
});
const libBrowserUtils = configure({
input: "./libs/System.Native.Browser/utils/index.ts",
output: [{
name: "libBrowserUtils",
format: "iife",
file: staticLibDestination + "/libSystem.Browser.Utils.js",
footer: await fs.readFile("./libs/System.Native.Browser/libSystem.Browser.Utils.footer.js"),
}],
terser: {
compress: {
toplevel: true,
keep_fnames,
}, mangle: {
toplevel: true,
keep_fnames,
reserved,
}
}
});
const dotnetDiagnosticsJS = configure({
input: "./libs/System.Native.Browser/diagnostics/index.ts",
output: [{
file: staticLibDestination + "/dotnet.diagnostics.js",
}],
terser: {
compress: {
module: true,
}, mangle: {
module: true,
keep_classnames,
}
}
});
const dotnetRuntimeJS = configure({
input: "./libs/System.Runtime.InteropServices.JavaScript.Native/dotnet.runtime.ts",
output: [{
file: staticLibDestination + "/dotnet.runtime.js",
}],
terser: {
compress: {
module: true,
}, mangle: {
module: true,
keep_classnames,
}
}
});
const libInteropJavaScriptNative = configure({
input: "./libs/System.Runtime.InteropServices.JavaScript.Native/native/index.ts",
output: [{
name: "libInteropJavaScriptNative",
format: "iife",
file: staticLibDestination + "/libSystem.Runtime.InteropServices.JavaScript.Native.js",
footer: await fs.readFile("./libs/System.Runtime.InteropServices.JavaScript.Native/libSystem.Runtime.InteropServices.JavaScript.Native.footer.js"),
}],
terser: {
compress: {
toplevel: true,
keep_fnames,
}, mangle: {
toplevel: true,
keep_fnames,
reserved,
}
}
});
const libBrowserHost = configure({
input: "./corehost/browserhost/host/index.ts",
output: [{
name: "libBrowserHost",
format: "iife",
file: staticLibDestination + "/libBrowserHost.js",
footer: await fs.readFile("./corehost/browserhost/libBrowserHost.footer.js"),
}],
terser: {
compress: {
toplevel: true,
keep_fnames,
}, mangle: {
toplevel: true,
keep_fnames,
reserved,
}
}
});
export default defineConfig([
dotnetJS,
dotnetDTS,
libNativeBrowser,
libBrowserUtils,
dotnetDiagnosticsJS,
dotnetRuntimeJS,
libInteropJavaScriptNative,
libBrowserHost,
]);
function configure({ input, output, terser }) {
return {
treeshake: !isDebug,
input,
output: output.map(o => {
return {
banner,
format: "es",
plugins: isDebug
? [iife2fe(), writeOnChangePlugin()]
: [terserPlugin(terser), iife2fe(), writeOnChangePlugin()],
sourcemap: true, //isDebug ? true : "hidden",
sourcemapPathTransform,
...o
};
}),
external: externalDependencies,
plugins: [
nodeResolve(),
consts(envConstants),
typescript({
tsconfig: "./tsconfig.json",
})
],
onwarn,
};
}