initial version.

feat: automatically run vite dev server when in Debugger mode.
feat: supports hotreload on both js frontend and .net backend.
This commit is contained in:
lchen committed 2026-10-21 14:11:15 +08:00
1 parent f925e00540
commit 5c81ed18b2
25 files changed
+743

No files matched your search

+52
View File
@@ -0,0 +1,52 @@
import js from "@eslint/js";
import globals from "globals";
import tseslint from "typescript-eslint";
import { defineConfig } from "eslint/config";
export default defineConfig([
tseslint.configs.recommended,
{
files: ["**/*.{js,mjs,cjs,ts,mts,cts}"],
plugins: { js },
extends: ["js/recommended"],
languageOptions: {
globals: {
...globals.browser,
__SITE_PATH__: 'readonly',
__SERVER_DATA__: 'readonly'
}
},
// add your custom rules here
rules: {
// 'indent': ['error', 4, {
// 'SwitchCase': 1
// }],
"indent": "off",
"linebreak-style": "off",
"max-len": "off",
//"no-console": [
// "error",
// { "allow": ["warn", "error"] }
//],
"no-console": "warn",
"no-continue": "off",
"no-debugger": "error",
"no-empty": "off",
"no-undef": "off",
"no-unused-vars": "off",
"no-redeclare": "off",
"no-mixed-operators": [
"error",
{
"groups": [["&&", "||"]]
}
],
//"no-nested-ternary": "off",
//"no-param-reassign": "off",
//"no-underscore-dangle": "off",
//"no-void": "off",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/triple-slash-reference": "off",
},
},
]);
+19
View File
@@ -0,0 +1,19 @@
{
"name": "source",
"private": true,
"type": "module",
"scripts": {
"dev:vite": "vite",
"build": "eslint && vite build"
},
"author": "Foresight Intelligence",
"license": "ISC",
"devDependencies": {
"@eslint/js": "^10.0.1",
"@types/node": "^26.6.5",
"eslint": "^10.13.0",
"globals": "^17.13.0",
"typescript-eslint": "^8.72.0",
"vite": "^8.3.4"
}
}
+4
View File
@@ -0,0 +1,4 @@
interface DetailItem {
id: number;
name: string;
}
+52
View File
@@ -0,0 +1,52 @@
/// <reference path="./global.d.ts" />
export interface ApiSuccess<T> {
errorCode: 0;
result: T;
tag?: unknown;
}
export interface ApiFailure {
errorCode: number;
errorMessage?: string;
resourceId?: string;
tag?: unknown;
}
export type ApiResult<T = unknown> = ApiSuccess<T> | ApiFailure;
export class ApiError extends Error {
public errorCode: number;
public errorMessage?: string;
constructor(errorCode: number, errorMessage?: string) {
super(errorMessage);
this.name = 'ApiError';
this.errorCode = errorCode;
this.errorMessage = errorMessage;
// Object.setPrototypeOf(this, ApiError.prototype);
}
override toString(): string {
return `[${this.name}]: ${this.errorMessage} (${this.errorCode})`;
}
get [Symbol.toStringTag](): string {
return 'ApiError';
}
}
export function isSuccess<T>(res: ApiResult<T>): res is ApiSuccess<T> {
return res.errorCode === 0;
}
export async function fetchApi<T>(url: string): Promise<T> {
const response = await fetch(url);
const json: ApiResult<T> = await response.json();
if (!isSuccess(json)) {
throw new ApiError(json.errorCode, json.errorMessage);
}
return json.result;
}
+21
View File
@@ -0,0 +1,21 @@
import { ApiError, fetchApi } from './helper';
const container = document.querySelector('#main');
if (container) {
try {
const detail = await fetchApi<DetailItem>('api/detail?id=11');
container.innerHTML = `
<div style="background: #f0f0f0; padding: 15px; border-radius: 12px">
<h3>Title: ${detail.name}</h3>
<p>ID: ${detail.id}</p>
</div>
`;
} catch (e) {
if (e instanceof ApiError) {
container.innerHTML = `<p>${e.errorCode}</p><pre>${e.errorMessage}</pre>`;
} else {
container.innerHTML = '<pre>unknown error</pre>';
}
}
}
+16
View File
@@ -0,0 +1,16 @@
import { ApiError } from "../helper";
declare global {
interface Window {
__SERVER_DATA__: ApiError
}
}
const errorContainer = document.querySelector('#error');
if (errorContainer instanceof HTMLElement) {
const err = window.__SERVER_DATA__;
errorContainer.innerText = `${err.errorCode}: ${err.errorMessage}`;
}
export { }
+11
View File
@@ -0,0 +1,11 @@
{
"include": [
"src/**/*.ts",
"vite.config.ts"
],
"compilerOptions": {
"types": [ "node" ],
"module": "esnext",
"moduleResolution": "bundler"
}
}
+21
View File
@@ -0,0 +1,21 @@
import { defineConfig } from 'vite';
import path from 'node:path';
export default defineConfig({
server: {
port: 5173,
cors: true,
strictPort: true
},
build: {
outDir: path.resolve(import.meta.dirname, '../wwwroot/dist'),
emptyOutDir: true,
manifest: true,
rollupOptions: {
input: {
main: path.resolve(import.meta.dirname, 'src/main.ts'),
error: path.resolve(import.meta.dirname, 'src/pages/error.ts')
}
}
}
});