chenhb13
2026-02-12 791bbd085b3669e16fa551a28221f3e317a1672b
feat(#deploy-test): 新增部署脚本相关
3个文件已修改
54 ■■■■■ 已修改文件
build.sh 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
eslint.config.js 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
vite.config.ts 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
build.sh
@@ -1,4 +1,12 @@
#! /bin/sh
npm install
npm run build
# 需要加入
. ~/.profile
SASS_BINARY_SITE=https://npm.taobao.org/mirrors/node-sass/ npm install --registry=http://npm.xiaopeng.local:7001
export CICD_STATIC_PATH=$(echo $CICD_STATIC_PATH) && npm run build
if [ $? != 0 ];then
    echo "build error"
    exit 1
fi
eslint.config.js
@@ -1,4 +1,3 @@
// eslint.config.js
import antfu from '@antfu/eslint-config'
// https://github.com/antfu/eslint-config
@@ -18,5 +17,7 @@
        'vue/component-definition-name-casing': 'off',
      },
    },
    // 新增:忽略指定文件
    ignores: ['vite.config.ts'],
  },
)
vite.config.ts
@@ -2,13 +2,34 @@
import { defineConfig, loadEnv } from 'vite'
import { createVitePlugins } from './build/plugins'
// https://vitejs.dev/config/
/**
 * 处理CDN路径的核心函数(移除TS类型标注,保留逻辑)
 * @param env 环境变量对象
 * @param mode 运行模式(development/production)
 * @returns 最终的base路径
 */
function getBasePath(env, mode) {
  // 1. 优先读取CI环境的CICD_STATIC_PATH,兜底用VITE_BASE_URL
  const cdnPath = process.env.CICD_STATIC_PATH || env.VITE_BASE_URL || ''
  // 2. 开发环境强制返回本地根路径
  if (mode === 'development') {
    return '/'
  }
  // 3. 生产/测试环境:补全CDN路径末尾的斜杠
  return cdnPath.endsWith('/') ? cdnPath : `${cdnPath}/`
}
// Vite核心配置(移除TS类型约束,保留原生JS写法)
export default defineConfig(({ mode }) => {
  // 根据当前工作目录中的 `mode` 加载 .env 文件
  const env = loadEnv(mode, __dirname, '') as ImportMetaEnv
  // 加载.env文件中的环境变量(移除TS类型断言)
  const env = loadEnv(mode, process.cwd(), '')
  return {
    base: env.VITE_BASE_URL,
    // 核心:使用原有逻辑生成base路径
    base: getBasePath(env, mode),
    // 插件配置(逻辑不变)
    plugins: createVitePlugins(env),
    resolve: {
      alias: {
@@ -17,10 +38,14 @@
    },
    server: {
      host: '0.0.0.0',
      port: 3000, // 可选:补充端口(按需调整)
      open: false,
    },
    build: {
      target: 'esnext',
      reportCompressedSize: false, // 启用/禁用 gzip 压缩大小报告
      reportCompressedSize: false,
      outDir: 'dist',
      assetsDir: 'assets',
    },
    optimizeDeps: {
      include: ['echarts', 'md-editor-v3', 'quill'],
@@ -28,7 +53,7 @@
    css: {
      preprocessorOptions: {
        scss: {
          api: 'modern',
          api: 'modern', // 移除TS的字面量类型断言
        },
      },
    },