涉及的文件很多,但主要是 PyCharm 自动重构 + 手动微调。 1. 使用 src-layout 结构组织项目,旨在更加规范地管理各个子包,并方便组织代码。 2. 可以使用 uv build 构建项目至 wheel。 3. 可以在 /webui 目录下使用 pnpm run build 来构建 WebUI,构建产物会生成在 /src/njupt_suan_api/static 目录下。同时,uv build 时会一同包含此目录下的 WebUI 构建产物,避免在用户侧执行构建。 4. 使用 typer 实现了命令行入口,代码位于 manage.py;命令行实现了现 main.py 的全部功能。
68 lines
1.6 KiB
TypeScript
68 lines
1.6 KiB
TypeScript
import {fileURLToPath, URL} from 'node:url'
|
|
|
|
import {defineConfig} from 'vite'
|
|
import vue from '@vitejs/plugin-vue'
|
|
import vueDevTools from 'vite-plugin-vue-devtools'
|
|
import vueJsx from '@vitejs/plugin-vue-jsx'
|
|
import AutoImport from 'unplugin-auto-import/vite'
|
|
import {NaiveUiResolver} from 'unplugin-vue-components/resolvers'
|
|
import Components from 'unplugin-vue-components/vite'
|
|
import path from 'node:path/posix'
|
|
import {readFileSync} from "node:fs";
|
|
import {resolve} from 'path';
|
|
|
|
// 从 package.json 里搞到 WebUI 版本号
|
|
const pkg = JSON.parse(readFileSync(resolve(__dirname, 'package.json'), 'utf-8'));
|
|
|
|
// https://vite.dev/config/
|
|
export default defineConfig({
|
|
plugins: [
|
|
vue(),
|
|
vueDevTools(),
|
|
vueJsx(),
|
|
AutoImport({
|
|
imports: ['vue', 'vue-router'],
|
|
}),
|
|
Components({
|
|
resolvers: [NaiveUiResolver()],
|
|
}),
|
|
],
|
|
define: {
|
|
__VERSION__: JSON.stringify(pkg.version)
|
|
},
|
|
build: {
|
|
rolldownOptions: {
|
|
input: {
|
|
index: path.resolve(__dirname, 'index.html'),
|
|
'index-schedule': path.resolve(__dirname, 'index-schedule.html'),
|
|
},
|
|
},
|
|
outDir: "../src/njupt_suan_api/static"
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
|
},
|
|
},
|
|
server: {
|
|
proxy: {
|
|
'/api': {
|
|
target: 'http://localhost:8000',
|
|
changeOrigin: true,
|
|
},
|
|
'/admin': {
|
|
target: 'http://localhost:8000',
|
|
changeOrigin: true,
|
|
},
|
|
'/ws': {
|
|
target: 'http://localhost:8000',
|
|
changeOrigin: true,
|
|
},
|
|
'/version': {
|
|
target: 'http://localhost:8000',
|
|
changeOrigin: true,
|
|
},
|
|
},
|
|
},
|
|
})
|