From fd4a7c90c6a9925a809fab758d8311854d06f147 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Thu, 31 Oct 2024 21:38:58 -0700 Subject: [PATCH] Add separate file option to allow importing to the global namespace. --- package.json | 2 +- src/global.ts | 5 +++++ tsconfig.json | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 src/global.ts diff --git a/package.json b/package.json index 40250a9..33d7a2e 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "url": "git+https://zoso.dev/libnemo.git" }, "scripts": { - "build": "rm -rf dist && tsc && esbuild dist/main.js --outfile=dist/main.min.js --target=es2022 --format=esm --platform=browser --bundle --minify --sourcemap", + "build": "rm -rf dist && tsc && esbuild main.min=dist/main.js global.min=dist/global.js --outdir=dist --target=es2022 --format=esm --platform=browser --bundle --minify --sourcemap", "test": "npm run build && node --test --env-file .env", "test:coverage": "npm run test -- --experimental-test-coverage", "test:coverage:report": "npm run test:coverage -- --test-reporter=lcov --test-reporter-destination=coverage.info && genhtml coverage.info --output-directory test/coverage && rm coverage.info && xdg-open test/coverage/index.html" diff --git a/src/global.ts b/src/global.ts new file mode 100644 index 0000000..083e4b9 --- /dev/null +++ b/src/global.ts @@ -0,0 +1,5 @@ +// SPDX-FileCopyrightText: 2024 Chris Duncan +// SPDX-License-Identifier: GPL-3.0-or-later + +import * as libnemo from './main.js' +Object.defineProperty(globalThis, 'libnemo', libnemo) diff --git a/tsconfig.json b/tsconfig.json index b544969..1dab653 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,6 +16,7 @@ }, "include": [ "src/main.ts", + "src/global.ts", "src/*", "src/**/*" ] -- 2.34.1