repos
/ status-django master

status-django

mirror archived upstream

Self-hostable uptime monitor and status page on Django: HTTP checks, Lighthouse audits, SEO crawls, and email and Discord alerts.

djangodockerhandcodedpythonself-hostedsqlitestatus-pageuptime-monitoringvite

1.7 KB · 55 lines · JavaScript Raw History
 1import { resolve } from "path";
 2import { defineConfig } from "vite";
 3
 4// datamaps pulls in d3 v3, whose top-level IIFE reads globals off `this`
 5// (this.document, this.navigator, etc.). Under ESM/strict `this` is undefined,
 6// crashing at load. Bind the IIFE's `this` to globalThis so those reads work.
 7//
 8// Datamaps itself also has a sloppy-mode bug: `hoverover = ...` is written in
 9// one function without ever being declared, relying on implicit global in
10// non-strict mode. Under ESM/strict that throws ReferenceError. Hoist a
11// declaration into the top-level IIFE so the bare assignment resolves.
12const fixDatamapsStrictMode = {
13  name: "fix-datamaps-strict-mode",
14  transform(code, id) {
15    if (id.includes("datamaps/node_modules/d3/d3.js")) {
16      return code.replace(/\}\(\);\s*$/, "}.call(globalThis);\n");
17    }
18    if (id.match(/datamaps\/dist\/datamaps\.[^/]+\.js$/)) {
19      return code.replace("var svg;", "var svg, hoverover;");
20    }
21  },
22};
23
24export default defineConfig({
25  plugins: [fixDatamapsStrictMode],
26  base: "/static/",
27  build: {
28    outDir: resolve(__dirname, "status/static"),
29    emptyOutDir: true,
30    rollupOptions: {
31      input: {
32        base: resolve(__dirname, "status/static_src/index.js"),
33        pages: resolve(__dirname, "pages/static_src/index.js"),
34        properties: resolve(__dirname, "properties/static_src/index.js"),
35      },
36      output: {
37        entryFileNames: "[name].js",
38        assetFileNames: (assetInfo) => {
39          if (/\.(png|jpg|gif|svg|webp)$/.test(assetInfo.name)) {
40            return "images/[name][extname]";
41          }
42          return "[name][extname]";
43        },
44      },
45    },
46  },
47  css: {
48    preprocessorOptions: {
49      scss: {
50        quietDeps: true,
51      },
52    },
53  },
54});