From 914b19ea58a9973cc02f8e01c72ce82582682cca Mon Sep 17 00:00:00 2001 From: kuaifan Date: Fri, 24 Feb 2023 00:30:07 +0800 Subject: [PATCH] no message --- .env.docker | 1 + app/Http/Controllers/IndexController.php | 20 +++++++-------- cmd | 3 +++ resources/views/main.blade.php | 14 +---------- vite.config.js | 32 +++++++++++++++--------- 5 files changed, 35 insertions(+), 35 deletions(-) diff --git a/.env.docker b/.env.docker index 50370288d..1ce4ffe06 100644 --- a/.env.docker +++ b/.env.docker @@ -8,6 +8,7 @@ APP_URL=http://localhost APP_ID= APP_IPPR= APP_PORT=2222 +APP_DEV_PORT= LOG_CHANNEL=stack LOG_LEVEL=debug diff --git a/app/Http/Controllers/IndexController.php b/app/Http/Controllers/IndexController.php index fd0afaebb..5a7992786 100755 --- a/app/Http/Controllers/IndexController.php +++ b/app/Http/Controllers/IndexController.php @@ -52,19 +52,19 @@ class IndexController extends InvokeController */ public function main() { - $hash = 'no'; - $path = public_path('js/hash'); - $murl = url('manifest.txt'); - if (file_exists($path)) { - $hash = trim(file_get_contents(public_path('js/hash'))); - if (strlen($hash) > 16) { - $hash = 'long'; - } + $scripts = []; + if (config('app.debug')) { + $port = env("APP_DEV_PORT"); + $scripts[] = ""; + } else { + $manifest = Base::json2array(file_get_contents(public_path('manifest.json'))); + $scripts[] = ""; + $scripts[] = ""; } return response()->view('main', [ 'version' => Base::getVersion(), - 'hash' => $hash - ])->header('Link', "<{$murl}>; rel=\"prefetch\""); + 'script' => implode("\n", $scripts), + ])->header('Link', "<" . url('manifest.txt') . ">; rel=\"prefetch\""); } /** diff --git a/cmd b/cmd index 6bfac7817..4d9341f46 100755 --- a/cmd +++ b/cmd @@ -99,6 +99,9 @@ run_compile() { if [ ! -d "./node_modules" ]; then npm install fi + if [ "$type" = "dev" ]; then + env_set APP_DEV_PORT $(rand 20001 30000) + fi run_exec php "php bin/run --mode=$type" supervisorctl_restart php # diff --git a/resources/views/main.blade.php b/resources/views/main.blade.php index ae0ad8990..61464ca26 100755 --- a/resources/views/main.blade.php +++ b/resources/views/main.blade.php @@ -37,19 +37,7 @@ -@php - if (config('app.debug')) { - echo ' '; - }else{ - $manifest = json_decode(file_get_contents(public_path('manifest.json')), true); - $css = $manifest['resources/assets/js/app.js']['css'][0]; - $css2 = $manifest['resources/assets/js/pages/manage/calendar.vue']['css'][0]; - $js = $manifest['resources/assets/js/app.js']['file']; - echo ' '; - echo ' '; - echo ' '; - } -@endphp +{!! $script !!} diff --git a/vite.config.js b/vite.config.js index 6baf42f74..a4c16ecfa 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,5 +1,5 @@ import {resolve} from "path"; -import {defineConfig} from 'vite' +import {defineConfig, loadEnv} from 'vite' import {createVuePlugin} from 'vite-plugin-vue2'; import vitePluginRequire from 'vite-plugin-require' import vitePluginFileCopy from 'vite-plugin-file-copy'; @@ -8,24 +8,26 @@ const argv = process.argv; const isElectron = argv.includes('--electron'); const publicPath = isElectron ? 'electron/public' : 'public'; -const serverHost = '0.0.0.0' -const serverPort = 22222 - export default defineConfig(({command, mode}) => { + const env = loadEnv(mode, process.cwd(), '') + const host = "0.0.0.0" + const port = parseInt(env['APP_DEV_PORT']) + return { base: '/', publicDir: publicPath, server: { - host: serverHost, - port: serverPort, + host, + port, + strictPort: false, }, resolve: { alias: { - '~element-ui': resolve(__dirname, './node_modules/element-ui'), - '~quill': resolve(__dirname, './node_modules/quill'), - '~quill-mention-hi': resolve(__dirname, './node_modules/quill-mention-hi'), - '../images': resolve(__dirname, command === 'serve' ? '/images' : './resources/assets/statics/public/images'), - '../css': resolve(__dirname, command === 'serve' ? '/css' : './resources/assets/statics/public/css') + '~element-ui': resolve(__dirname, 'node_modules/element-ui'), + '~quill': resolve(__dirname, 'node_modules/quill'), + '~quill-mention-hi': resolve(__dirname, 'node_modules/quill-mention-hi'), + '../images': resolve(__dirname, command === 'serve' ? '/images' : 'resources/assets/statics/public/images'), + '../css': resolve(__dirname, command === 'serve' ? '/css' : 'resources/assets/statics/public/css') }, extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'] }, @@ -36,15 +38,21 @@ export default defineConfig(({command, mode}) => { manifest: true, outDir: publicPath, assetsDir: "js/build", + emptyOutDir: false, + copyPublicDir: false, rollupOptions: { input: 'resources/assets/js/app.js', }, + brotliSize: false, chunkSizeWarningLimit: 3000, }, plugins: [ createVuePlugin(), vitePluginRequire(), - vitePluginFileCopy([{src: 'resources/assets/statics/public', dest: publicPath}]), + vitePluginFileCopy([{ + src: resolve(__dirname, 'resources/assets/statics/public'), + dest: resolve(__dirname, publicPath) + }]), ] }; });