fix
This commit is contained in:
1 parent
f4cd61ec75
commit
ba4b34b290
3 files changed
+78
-32
No files matched your search
@@ -28,28 +28,36 @@ jobs:
|
||||
cache: 'npm'
|
||||
cache-dependency-path: frontend/package-lock.json
|
||||
|
||||
# 安装依赖并构建
|
||||
- name: Install dependencies and build
|
||||
# 缓存node_modules和构建输出
|
||||
- name: Cache dependencies and build
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
frontend/node_modules
|
||||
frontend/production
|
||||
key: ${{ runner.os }}-frontend-${{ hashFiles('frontend/package-lock.json', 'frontend/src/**/*', 'frontend/vite.config.ts') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-frontend-${{ hashFiles('frontend/package-lock.json') }}
|
||||
${{ runner.os }}-frontend-
|
||||
|
||||
# 安装依赖
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
cd frontend
|
||||
npm ci
|
||||
npm run build:prod
|
||||
|
||||
# 并行执行类型检查和构建
|
||||
- name: Type check and build
|
||||
run: |
|
||||
cd frontend
|
||||
# 并行执行类型检查和构建以节省时间
|
||||
npm run type-check &
|
||||
npm run build:prod &
|
||||
wait
|
||||
# 检查构建结果
|
||||
echo "Build completed, checking production directory:"
|
||||
ls -la production/
|
||||
|
||||
# 设置目录权限以允许写入
|
||||
- name: Set directory permissions
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.HOST_PI }}
|
||||
username: pi
|
||||
password: ${{ secrets.PASS_PI }}
|
||||
port: 22
|
||||
script: |
|
||||
sudo chown -R pi:www-data /home/pi/lm-www/frontend
|
||||
sudo chmod -R 775 /home/pi/lm-www/frontend
|
||||
|
||||
# 将构建产物传输到服务器
|
||||
- name: Copy build files to server
|
||||
uses: appleboy/scp-action@v0.1.7
|
||||
@@ -61,8 +69,8 @@ jobs:
|
||||
source: "frontend/production/*"
|
||||
target: "/home/pi/lm-www/"
|
||||
|
||||
# 设置文件权限并重载nginx配置
|
||||
- name: Set permissions and reload nginx
|
||||
# 一次性完成部署和配置
|
||||
- name: Deploy and configure server
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.HOST_PI }}
|
||||
@@ -70,21 +78,32 @@ jobs:
|
||||
password: ${{ secrets.PASS_PI }}
|
||||
port: 22
|
||||
script: |
|
||||
# 设置正确的文件权限
|
||||
echo "Setting correct file permissions..."
|
||||
echo "Starting deployment configuration..."
|
||||
|
||||
# 设置目录权限
|
||||
echo "Setting directory permissions..."
|
||||
sudo chown -R pi:www-data /home/pi/lm-www/frontend
|
||||
sudo chmod -R 775 /home/pi/lm-www/frontend
|
||||
|
||||
# 等待文件传输完成后设置最终权限
|
||||
echo "Setting final permissions..."
|
||||
sudo chown -R www-data:www-data /home/pi/lm-www/frontend/
|
||||
sudo chmod -R 755 /home/pi/lm-www/frontend/
|
||||
|
||||
# 检查nginx配置文件语法
|
||||
echo "Checking nginx configuration..."
|
||||
sudo nginx -t
|
||||
|
||||
# 重载nginx配置
|
||||
echo "Reloading nginx..."
|
||||
# 检查nginx配置并重载
|
||||
echo "Testing and reloading nginx..."
|
||||
if sudo nginx -t; then
|
||||
sudo nginx -s reload
|
||||
echo "Nginx reloaded successfully"
|
||||
|
||||
# 检查nginx状态
|
||||
echo "Checking nginx status..."
|
||||
# 验证nginx状态
|
||||
if sudo systemctl is-active --quiet nginx; then
|
||||
echo "✅ Frontend deployment completed successfully!"
|
||||
else
|
||||
echo "⚠️ Warning: Nginx service may have issues"
|
||||
sudo systemctl status nginx --no-pager -l
|
||||
|
||||
echo "Frontend deployment completed successfully!"
|
||||
fi
|
||||
else
|
||||
echo "❌ Nginx configuration test failed!"
|
||||
exit 1
|
||||
fi
|
||||
@@ -1,5 +1,5 @@
|
||||
# 正式环境接口地址 - 自动匹配当前域名
|
||||
VITE_API_BASE_URL = '/api'
|
||||
VITE_API_BASE_URL = ''
|
||||
|
||||
# 正式环境打包名称
|
||||
VITE_OUTDIR='production'
|
||||
|
||||
+29
-2
@@ -45,9 +45,27 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
|
||||
verbose: true, // 显示压缩日志
|
||||
disable: !isProd, // 非生产环境禁用
|
||||
deleteOriginFile: false, // 不删除源文件
|
||||
threshold: 10240, // 文件大小10KB才压缩
|
||||
threshold: 1024, // 文件大小1KB才压缩(降低阈值)
|
||||
algorithm: 'gzip', // 压缩算法
|
||||
ext: '.gz', // 压缩文件扩展名
|
||||
compressionOptions: {
|
||||
level: 9, // 最高压缩级别
|
||||
}
|
||||
}),
|
||||
|
||||
// 添加Brotli压缩支持(更高效的压缩算法)
|
||||
isProd && viteCompression({
|
||||
verbose: true,
|
||||
disable: !isProd,
|
||||
deleteOriginFile: false,
|
||||
threshold: 1024,
|
||||
algorithm: 'brotliCompress',
|
||||
ext: '.br',
|
||||
compressionOptions: {
|
||||
params: {
|
||||
[require('zlib').constants.BROTLI_PARAM_QUALITY]: 11, // 最高质量
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
||||
// 打包分析插件(仅在显式启用时生效;容器/CI 默认不打开浏览器)
|
||||
@@ -112,10 +130,19 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
|
||||
compress: {
|
||||
drop_console: isProd, // 生产环境移除console
|
||||
drop_debugger: isProd, // 生产环境移除debugger
|
||||
pure_funcs: isProd ? ['console.log'] : [] // 移除纯函数调用
|
||||
pure_funcs: isProd ? ['console.log'] : [], // 移除纯函数调用
|
||||
// 额外的压缩优化
|
||||
dead_code: true, // 移除无用代码
|
||||
keep_infinity: true, // 保持Infinity
|
||||
toplevel: isProd, // 顶级作用域压缩
|
||||
},
|
||||
mangle: {
|
||||
toplevel: isProd, // 顶级作用域变量名压缩
|
||||
}
|
||||
},
|
||||
rollupOptions: { // Rollup打包配置
|
||||
// 启用构建缓存以提升重复构建速度
|
||||
cache: isProd, // 生产环境启用Rollup缓存
|
||||
output: {
|
||||
// 优化的手动分块策略
|
||||
manualChunks: {
|
||||
|
||||
Reference in new issue
Block a user