From b083271b923cd05393868071e052cc42f5991345 Mon Sep 17 00:00:00 2001 From: clfreville2 Date: Tue, 31 Oct 2023 20:09:19 +0100 Subject: [PATCH] Allow changing the code at build time --- README.md | 12 +++++++++++- src/digicode.ts | 2 +- tsconfig.json | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d15f97f..ee1a6ab 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # naive-keypad -# Build the browser application +## Build the browser application Ensure you have [Node.js](https://nodejs.org) installed. Then run: @@ -8,3 +8,13 @@ Ensure you have [Node.js](https://nodejs.org) installed. Then run: npm install npm run build ``` + +Copy the contents of the `dist` directory to your web server, and there you go! + +## Changing the code + +You may during the build process override the code of the keypad: + +```sh +VITE_KEYPAD_CODE=7894 npm run build +``` diff --git a/src/digicode.ts b/src/digicode.ts index 5967ad4..960cc97 100644 --- a/src/digicode.ts +++ b/src/digicode.ts @@ -1,6 +1,6 @@ import './style.css'; -const CODE = '1234'; +const CODE = import.meta.env.VITE_KEYPAD_CODE || '1234'; let builder = ''; const display = document.getElementById('display') as HTMLDivElement; diff --git a/tsconfig.json b/tsconfig.json index 75abdef..736af3f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,6 +4,7 @@ "useDefineForClassFields": true, "module": "ESNext", "lib": ["ES2020", "DOM", "DOM.Iterable"], + "types": ["vite/client"], "skipLibCheck": true, /* Bundler mode */