update app-template

This commit is contained in:
abearxiong 2025-02-27 09:46:32 +08:00
parent 11ac3a22ab
commit 0297d69cdb
9 changed files with 564 additions and 247 deletions

View File

@ -3,6 +3,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Apps</title>
<link rel="stylesheet" href="./src/assets/index.css">
<style>
html,
body {
@ -23,6 +24,7 @@
<body>
<div id="ai-root"></div>
<div id="ai-bot-root"></div>
</body>
<script src="./src/main.ts" type="module"></script>

View File

@ -3,6 +3,7 @@
"version": "0.0.1",
"description": "",
"main": "index.js",
"basename": "/me/app/",
"scripts": {
"dev": "vite",
"dev:web": "cross-env WEB_DEV=true vite --mode web",
@ -33,6 +34,7 @@
"@kevisual/router": "0.0.6-alpha-5",
"@kevisual/store": "0.0.1-alpha.10",
"@kevisual/types": "^0.0.6",
"@tailwindcss/vite": "^4.0.9",
"@types/react": "^19.0.8",
"@types/react-dom": "^19.0.3",
"@vitejs/plugin-basic-ssl": "^1.2.0",
@ -40,6 +42,7 @@
"cross-env": "^7.0.3",
"esbuild": "^0.25.0",
"react": "^19.0.0",
"tailwindcss": "^4.0.9",
"vite": "^6.1.0"
}
}

770
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,11 @@
import type { Page } from '@kevisual/store/page';
import type { QueryRouterServer } from '@kevisual/router';
import { basename } from './modules/basename';
export const page = useContextKey('page', () => {
return new window.Page({
basename: '',
basename,
}) as unknown as Page;
});
export const app = useContextKey('app', () => {
console.error('app not found');
return null as unknown as QueryRouterServer;

10
src/assets/index.css Normal file
View File

@ -0,0 +1,10 @@
@import 'tailwindcss';
@config "../../tailwind.config.js";
#ai-bot-root {
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: -100px;
z-index: 9999;
}

View File

@ -1,9 +1,11 @@
import { page, app } from './app.ts';
import { basename } from './modules/basename.ts';
export const render = ({ renderRoot }) => {
renderRoot.innerHTML = `
<h1>Hello, World!</h1>
`;
};
console.log('basename', basename, page, app);
if (page) {
page.addPage('/app-template', 'home');
@ -12,6 +14,13 @@ if (page) {
renderRoot: document.getElementById('ai-root'),
});
});
page.addPage('', 'index');
page.subscribe('index', () => {
const root = document.getElementById('ai-root') as HTMLElement;
root.innerHTML = `
<h1>Hello, World!</h1>
`;
});
}
if (app) {

2
src/modules/basename.ts Normal file
View File

@ -0,0 +1,2 @@
// @ts-ignore
export const basename = DEV_SERVER ? '/' : BASE_NAME;

3
tailwind.config.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = {
root: '#ai-root',
};

View File

@ -3,11 +3,14 @@ import basicSsl from '@vitejs/plugin-basic-ssl';
// import react from '@vitejs/plugin-react';
import dayjs from 'dayjs';
import path from 'path';
import tailwindcss from '@tailwindcss/vite'
import pkgs from './package.json' with { type: 'json' };
const isDev = process.env.NODE_ENV === 'development';
const isWebDev = process.env.WEB_DEV === 'true';
const BUILD_TIME = dayjs().format('YYYY-MM-DD HH:mm:ss');
let plugins = [];
const basename = pkgs.basename;
let plugins = [tailwindcss(),];
if (!isWebDev) {
// 在bolt的web开发环境下不需要ssl
@ -22,10 +25,11 @@ export default defineConfig({
'@': path.resolve(__dirname, './src'),
},
},
base: isDev ? '/' : './',
base: isDev ? '/' : basename,
define: {
DEV_SERVER: JSON.stringify(isDev),
BUILD_TIME: JSON.stringify(BUILD_TIME),
BASE_NAME: JSON.stringify(basename),
},
optimizeDeps: {
exclude: ['react'], // 排除 react 和 react-dom 以避免打包