Skip to content

Commit f001b2d

Browse files
committed
Use package name from package.json as the global name for UMD
1 parent d9a42a4 commit f001b2d

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
lines changed

scripts/build.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import { resolve, normalize } from "node:path";
44
import { fileURLToPath } from "node:url";
55
import { readFileSync, writeFileSync } from "node:fs";
6-
import { createRequire } from "node:module";
7-
8-
const pkg = createRequire(import.meta.url)("../package.json");
6+
import pkg from "../package.json" with { type: "json" };
97

108
const ROOT = fileURLToPath(new URL("..", import.meta.url));
119
const TYPES_ROOT_FILE = resolve(ROOT, normalize(pkg.exports["."].types));

scripts/copy-umd-file.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { parseArgs } from "node:util";
2-
import { createRequire } from "node:module";
2+
import pkg from "../package.json" with { type: "json" };
33
import { fileURLToPath } from "node:url";
44
import { resolve, dirname, join, basename } from "node:path";
55
import { copyFile } from "node:fs/promises";
@@ -12,7 +12,6 @@ if (to === undefined) {
1212
throw new Error("required argument `to` missing");
1313
}
1414

15-
const pkg = createRequire(import.meta.url)("../package.json");
1615
const umdAbsolutePath = resolve(
1716
dirname(fileURLToPath(import.meta.url)),
1817
join("..", pkg.jsdelivr),

vite.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { defineConfig } from "vite";
2+
import pkg from "./package.json" with { type: "json" };
23

34
const indexInput = "src/index.ts";
45
const tokenInput = "src/token.ts";
6+
const globalVarName = pkg.name;
57

68
export default defineConfig(({ mode }) => {
79
const isCJSBuild = mode === "production";
8-
const globalVarName = "meilisearch";
910

1011
return {
1112
build: {

0 commit comments

Comments
 (0)