vite.config.cdn.ts 1.47 KB
import { loadEnv, mergeConfig } from "vite";
import baseConfig from "./vite.config.base";
import configCompressPlugin from "./plugin/compress";
import configVisualizerPlugin from "./plugin/visualizer";
import configArcoResolverPlugin from "./plugin/arcoResolver";
import configImageminPlugin from "./plugin/imagemin";
import VitePluginOss from "vite-plugin-oss";

const config = loadEnv("production", "");

const ossPath = `vendor/user/asset${new Date()
  .toLocaleString("zh")
  .slice(0, 20)
  .replace(/[\s/:]/g, "")}`;
export default mergeConfig(
  {
    mode: "production",
    base: config.VITE_OSS_HOST,
    server: {
      https: true
    },
    plugins: [
      configCompressPlugin("gzip"),
      configVisualizerPlugin(),
      configArcoResolverPlugin(),
      configImageminPlugin(),
      VitePluginOss({
        from: `./dist/${ossPath}/**`,
        accessKeyId: config.VITE_OSS_ACCESS_KEY,
        accessKeySecret: config.VITE_OSS_ACCESS_SECRET,
        bucket: config.VITE_OSS_BUCKET,
        region: config.VITE_OSS_REGION,
        quitWpOnError: true,
        deleteOrigin: true,
        deleteEmptyDir: true
      })
    ],
    build: {
      assetsDir: ossPath,
      rollupOptions: {
        output: {
          manualChunks: {
            arco: ["@arco-design/web-vue"],
            chart: ["echarts", "vue-echarts"],
            vue: ["vue", "vue-router", "pinia", "@vueuse/core", "vue-i18n"]
          }
        }
      },
      chunkSizeWarningLimit: 2000
    }
  },
  baseConfig
);