From da2ca1ece6699c4e55696ad4fb6541c9e67ac0a8 Mon Sep 17 00:00:00 2001 From: Leon Yu Date: Sat, 21 Sep 2024 22:07:36 -0400 Subject: [PATCH] Webpack config update --- public/index.html | 2 +- public/qr.html | 8 ++++++-- src/index.ts | 9 +-------- webpack.config.js | 19 ------------------- webpack.config.mjs | 19 +++++++++++++++++++ 5 files changed, 27 insertions(+), 30 deletions(-) delete mode 100644 webpack.config.js create mode 100644 webpack.config.mjs diff --git a/public/index.html b/public/index.html index 4ea613c..3158283 100644 --- a/public/index.html +++ b/public/index.html @@ -21,7 +21,7 @@ - + diff --git a/public/qr.html b/public/qr.html index 53471da..cf03f9c 100644 --- a/public/qr.html +++ b/public/qr.html @@ -19,10 +19,14 @@ + - diff --git a/src/index.ts b/src/index.ts index 2be8815..da2ebdc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,15 +1,12 @@ import QRView from './QRView'; -declare const fetchCheckIP: Promise; - -async function init(ipPromise: Promise): Promise { +export function init(ipAddress: string): void { const qrDiv = document.querySelector('#qr'); if (qrDiv == null) { throw new Error('Content DIV does not exist.') } const view = new QRView(qrDiv); try { - const ipAddress = await ipPromise; if (ipAddress) { view.updateInput(`CLIENT_IP:${ipAddress}`); } @@ -17,7 +14,3 @@ async function init(ipPromise: Promise): Promise { view.updateInput(String(err)); } } - -document.addEventListener('DOMContentLoaded', () => { - void init(fetchCheckIP); -}); diff --git a/webpack.config.js b/webpack.config.js deleted file mode 100644 index 6717692..0000000 --- a/webpack.config.js +++ /dev/null @@ -1,19 +0,0 @@ - -const path = require('path'); - -module.exports = { - mode: 'production', - entry: './src/', - output: { - filename: 'app.js', - path: path.resolve(__dirname, 'dist/js'), - }, - resolve: { - extensions: ['.tsx', '.ts', '.jsx', '.js'], - }, - module: { - rules: [ - { test: /\.tsx?$/, use: 'ts-loader' }, - ] - } -}; diff --git a/webpack.config.mjs b/webpack.config.mjs new file mode 100644 index 0000000..f56501a --- /dev/null +++ b/webpack.config.mjs @@ -0,0 +1,19 @@ + +import path from 'node:path'; +import { env } from 'node:process'; + +export default { + mode: env.NODE_ENV == 'production' ? 'production' : 'development', + entry: './src/', + resolve: { extensions: ['.ts', '.js'] }, + module: { + rules: [ + { test: /\.([cm]?ts|tsx)$/, loader: 'ts-loader' }, + ], + }, + output: { + filename: 'bundle.js', + path: path.resolve(import.meta.dirname, 'dist'), + library: { name: 'bundle', type: 'umd' }, + }, +};