-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathrollup.config.js
More file actions
80 lines (77 loc) · 2.15 KB
/
rollup.config.js
File metadata and controls
80 lines (77 loc) · 2.15 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
import typescript from "rollup-plugin-typescript2";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import { terser } from "rollup-plugin-terser";
import wasm from "rollup-plugin-wasm";
// Rewrites the worker URL in worker.js so the bundle loads the self-contained
// feascript-worker.esm.js (a sibling of feascript.esm.js in dist/) instead of
// the source wrapper.js. This keeps source-mode loading correct while making
// the bundle work from any host path (CDN or local dev server).
const rewriteWorkerUrl = {
name: "rewrite-worker-url",
renderChunk(code, chunk) {
// Replace the source-relative wrapper.js path with the dist-sibling path so the
// bundle resolves feascript-worker.esm.js correctly from any host path.
if (/feascript\.(esm|cjs|umd)\.js$/.test(chunk.fileName)) {
return {
code: code.replace('"./wrapper.js"', '"./feascript-worker.esm.js"'),
map: null,
};
}
return null;
},
};
const plugins = [
rewriteWorkerUrl,
resolve({
browser: true,
preferBuiltins: false,
}),
commonjs(),
wasm({
maxFileSize: 14000000,
}),
typescript({
useTsconfigDeclarationDir: true,
clean: true,
}),
terser(),
];
export default [
// Main library bundle
{
input: "src/index.js",
output: [
{
file: "dist/feascript.cjs.js",
format: "cjs",
sourcemap: true,
},
{
file: "dist/feascript.esm.js",
format: "esm",
sourcemap: true,
},
{
file: "dist/feascript.umd.js",
format: "umd",
name: "FEAScript",
sourcemap: true,
},
],
plugins,
external: (id) => id === "@kitware/vtk.js" || id.startsWith("@kitware/vtk.js/") || id === "plotly.js",
},
// Self-contained worker bundle: bundles all bare-specifier deps (mathjs, @stdlib/*)
// so the worker file has no bare specifiers and works in Firefox, where module
// workers do not inherit the page's import map.
{
input: "src/workers/wrapper.js",
output: {
file: "dist/feascript-worker.esm.js",
format: "esm",
sourcemap: true,
},
plugins,
},
];