Skip to content

Commit

Permalink
Webpack config update
Browse files Browse the repository at this point in the history
  • Loading branch information
leonyu committed Sep 22, 2024
1 parent c8d1487 commit 342a1e5
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 30 deletions.
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<link rel="stylesheet" href="/css/penguin.css">

<link rel="stylesheet" href="https://cloud.leonyu.net/boxing/css/ui.css">
<script defer src="https://cloud.leonyu.net/boxing/js/app.js"></script>
<script defer src="https://cloud.leonyu.net/boxing/js/bundle.js"></script>
</head>

<body>
Expand Down
8 changes: 6 additions & 2 deletions public/qr.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css">
<link rel="stylesheet" href="/css/penguin.css">

<script defer src="/js/bundle.js"></script>
<script>
const fetchCheckIP = fetch('https://cloud.leonyu.net/boxing/', { method: 'HEAD' }).then((res) => res.headers.get('X-Request-IP') || '');
addEventListener('DOMContentLoaded', () => {
fetch('https://cloud.leonyu.net/boxing/', { method: 'HEAD' })
.then((res) => res.headers.get('X-Request-IP') || '')
.then((ipAdress) => { bundle.init(ipAdress); });
});
</script>
<script defer src="/js/app.js"></script>
</head>

<body>
Expand Down
9 changes: 1 addition & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
import QRView from './QRView';

declare const fetchCheckIP: Promise<string>;

async function init(ipPromise: Promise<string>): Promise<void> {
export function init(ipAddress: string): void {
const qrDiv = document.querySelector<HTMLDivElement>('#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}`);
}
} catch (err) {
view.updateInput(String(err));
}
}

document.addEventListener('DOMContentLoaded', () => {
void init(fetchCheckIP);
});
19 changes: 0 additions & 19 deletions webpack.config.js

This file was deleted.

19 changes: 19 additions & 0 deletions webpack.config.mjs
Original file line number Diff line number Diff line change
@@ -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'] },
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' },
},
};

0 comments on commit 342a1e5

Please sign in to comment.