forked from UniversalViewer/universalviewer
-
Notifications
You must be signed in to change notification settings - Fork 3
/
esbuild.mjs
83 lines (77 loc) · 2.27 KB
/
esbuild.mjs
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
import path from "path";
import { build } from "esbuild";
import { lessLoader } from "esbuild-plugin-less";
import svg from "esbuild-plugin-svg";
import fs from "fs";
import LessPluginCleanCSS from "less-plugin-clean-css";
const watch = process.argv[2] === "--watch";
const pkg = JSON.parse(fs.readFileSync("./package.json").toString());
// These are NPM packages that don't work with external bundlers without configuration.
// To avoid confusion, this will ensure they are included in the ESM bundle.
const bundledPackages = [
"jquery",
"jsviews",
"xss",
"@iiif/vocabulary",
"@edsilv/jquery-plugins",
];
// This plugin will ensure that mediaelement css is loaded correctly. It's currently using a webpack specific
// format.
let resolveMediaElement = {
name: "resolve-media-element",
setup(build) {
// Hack for resolution of webpack specific.
build.onResolve({ filter: /~mediaelement/ }, (args) => {
const t = args.path.split("~mediaelement")[1];
return {
path: path.join(process.cwd(), "./node_modules/mediaelement", t),
};
});
},
};
async function main() {
await build({
// Enables code splitting, similar to webpack.
splitting: true,
outdir: path.resolve(process.cwd(), "dist/esm"),
entryPoints: [path.resolve(process.cwd(), "src/index.ts")],
bundle: true,
target: "es2020",
format: "esm",
globalName: "UV",
watch,
minify: true,
external: [
...Object.keys(pkg.dependencies).filter(
(t) => t.indexOf(bundledPackages) !== -1
),
],
plugins: [
resolveMediaElement,
lessLoader({
paths: [
"node_modules/",
"./src/content-handlers/iiif/modules/uv-shared-module/img",
"./src/content-handlers/iiif/modules/uv-pagingheaderpanel-module/img",
"./src/content-handlers/iiif/modules/uv-openseadragoncenterpanel-module/img",
"./src/content-handlers/iiif/modules/uv-searchfooterpanel-module/img",
],
math: "always",
javascriptEnabled: true,
plugins: [
new LessPluginCleanCSS({
advanced: true,
level: 2,
}),
],
}),
svg(),
],
loader: {
".ts": "ts",
".png": "dataurl",
".gif": "dataurl",
},
});
}
main();