feat: 优化开发环境配置

This commit is contained in:
kuaifan 2025-10-08 04:35:08 +00:00
parent 7c21782ab5
commit a8d2d6f13f
6 changed files with 29 additions and 5 deletions

View File

@ -4,7 +4,6 @@ on:
push:
branches:
- "pro"
- "dev"
jobs:
check-version:

View File

@ -61,6 +61,10 @@ class IndexController extends InvokeController
$array = Base::json2array(file_get_contents($hotFile));
$style = null;
$script = preg_replace("/^(\/\/(.*?))(:\d+)?\//i", "$1:" . $array['APP_DEV_PORT'] . "/", asset_main("resources/assets/js/app.js"));
$proxyUri = env('VSCODE_PROXY_URI');
if (is_string($proxyUri) && preg_match('/^https?:\/\//i', $proxyUri)) {
$script = preg_replace('/^(https?:\/\/|\/\/)[^\/]+/', rtrim($proxyUri, '/'), $script, 1);
}
} else {
$array = Base::json2array(file_get_contents($manifestFile));
$style = asset_main($array['resources/assets/js/app.js']['css'][0]);

10
cmd
View File

@ -175,7 +175,13 @@ web_build() {
fi
if [ "$type" = "dev" ]; then
echo "<script>window.location.href=window.location.href.replace(/:\d+/, ':' + $(env_get APP_PORT))</script>" > ./index.html
env_set APP_DEV_PORT $(rand 20001 30000)
if [[ -z "$(env_get APP_DEV_PORT)" ]] || [[ -z "${VSCODE_PROXY_URI:-}" ]]; then
env_set APP_DEV_PORT $(rand 20001 30000)
fi
if [ -n "${VSCODE_PROXY_URI:-}" ]; then
VSCODE_PROXY_URI=$(APP_DEV_PORT="$(env_get APP_DEV_PORT)" node -p "process.env.VSCODE_PROXY_URI.replace(/\{\{port\}\}/g, process.env.APP_DEV_PORT || '')")
fi
env_set VSCODE_PROXY_URI "${VSCODE_PROXY_URI:-}"
fi
switch_debug "$type"
#
@ -479,7 +485,7 @@ handle_install() {
for vol in "${volumes[@]}"; do
tmp_path="${WORK_DIR}/${vol}"
mkdir -p "${tmp_path}"
chmod -R 775 "${tmp_path}"
find "${tmp_path}" -type d -exec chmod 775 {} \;
rm -f "${tmp_path}/dootask.lock"
cmda="${cmda} -v ${tmp_path}:/usr/share/${vol}"
cmdb="${cmdb} touch /usr/share/${vol}/dootask.lock &&"

View File

@ -2,6 +2,8 @@ const isElectron = !!(window && window.process && window.process.type && window.
const isEEUIApp = window && window.navigator && /eeui/i.test(window.navigator.userAgent);
const isSoftware = isElectron || isEEUIApp;
document.getElementById("app")?.setAttribute("data-preload", "false");
import {languageName, switchLanguage as $L} from "./language";
import {isLocalHost} from "./components/Replace/utils";

View File

@ -34,7 +34,7 @@
<body>
@extends('ie')
<div id="app" data-preload="false">
<div id="app" data-preload="init">
<div class="app-view-loading no-dark-content">
<div>
<div>PAGE LOADING</div>

15
vite.config.js vendored
View File

@ -22,6 +22,7 @@ export default defineConfig(({command, mode}) => {
const env = loadEnv(mode, process.cwd(), '')
const host = "0.0.0.0"
const port = parseInt(env['APP_DEV_PORT'])
const proxy_uri = env['VSCODE_PROXY_URI']
if (command === 'serve') {
const hotFile = path.resolve(__dirname, 'public/hot')
@ -80,6 +81,17 @@ export default defineConfig(({command, mode}) => {
})
}
const serverHmr = {}
if (/^https?:\/\//i.test(proxy_uri)) {
const proxyUri = new URL(proxy_uri)
if (proxyUri) {
Object.assign(serverHmr, {
host: proxyUri.host,
clientPort: proxyUri.port || (/^https/.test(proxy_uri) ? 443 : 80)
})
}
}
return {
base: basePath,
publicDir: publicPath,
@ -98,7 +110,8 @@ export default defineConfig(({command, mode}) => {
'**/language/**',
'**/electron/**',
]
}
},
hmr: serverHmr
},
resolve: {
alias: {