// vite.config.ts
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'file:///E:/code/vue3-h5-stock/node_modules/vite/dist/node/index.js'
import vue from 'file:///E:/code/vue3-h5-stock/node_modules/@vitejs/plugin-vue/dist/index.mjs'
import AutoImport from 'file:///E:/code/vue3-h5-stock/node_modules/unplugin-auto-import/dist/vite.js'
import Components from 'file:///E:/code/vue3-h5-stock/node_modules/unplugin-vue-components/dist/vite.js'
import { VantResolver } from 'file:///E:/code/vue3-h5-stock/node_modules/@vant/auto-import-resolver/dist/index.esm.mjs'
import externalGlobals from 'file:///E:/code/vue3-h5-stock/node_modules/rollup-plugin-external-globals/index.js'
import { createHtmlPlugin } from 'file:///E:/code/vue3-h5-stock/node_modules/vite-plugin-html/dist/index.mjs'
import viteCompression from 'file:///E:/code/vue3-h5-stock/node_modules/vite-plugin-compression/dist/index.mjs'
var __vite_injected_original_import_meta_url = 'file:///E:/code/vue3-h5-stock/vite.config.ts'
function getDir() {
  const d = /* @__PURE__ */ new Date()
  const yy = d.getFullYear()
  const MM = d.getMonth() + 1 >= 10 ? d.getMonth() + 1 + '' : '0' + (d.getMonth() + 1)
  const DD = d.getDate() >= 10 ? d.getDate() + '' : '0' + d.getDate()
  const h = d.getHours() >= 10 ? d.getHours() + '' : '0' + d.getHours()
  const mm = d.getMinutes() >= 10 ? d.getMinutes() + '' : '0' + d.getMinutes()
  const version = yy + MM + DD + h + mm
  return version + '/static'
}
var dir = getDir()
var cdn = {
  css: ['https://unpkg.com/vue3-pdf-app@1.0.3/dist/icons/main.css'],
  js: [
    'https://unpkg.com/vue@3.4.21/dist/vue.global.js',
    'https://unpkg.com/pinia@2.1.7',
    'https://unpkg.com/vue-router@4.3.0',
    'https://unpkg.com/vant@4.9.1'
  ]
}
var externalGlobalsObj = {
  vue: 'Vue',
  pinia: 'Pinia',
  'vue-router': 'VueRouter',
  vant: 'Vant'
}
var vite_config_default = defineConfig(({ mode }) => {
  console.log(mode)
  const isProduction = mode === 'production'
  return {
    plugins: [
      vue(),
      AutoImport({
        resolvers: [VantResolver()]
      }),
      Components({
        resolvers: [VantResolver()]
      }),
      createHtmlPlugin({
        inject: {
          data: {
            cdnCss: isProduction ? cdn.css : [],
            cdnJs: isProduction ? cdn.js : []
          }
        }
      }),
      //在plugins配置数组里添加gzip插件
      viteCompression({
        verbose: true,
        disable: false,
        threshold: 10240,
        algorithm: 'gzip',
        ext: '.gz'
      }),
      {
        ...externalGlobals(externalGlobalsObj),
        enforce: 'post',
        apply: 'build'
      }
    ],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', __vite_injected_original_import_meta_url)),
        '/img': fileURLToPath(new URL('./src/assets/img', __vite_injected_original_import_meta_url))
      },
      extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
    },
    build: {
      target: 'es2015',
      assetsDir: dir,
      minify: 'terser',
      // 必须开启：使用terserOptions才有效果
      terserOptions: {
        compress: {
          keep_infinity: true,
          // 防止 Infinity 被压缩成 1/0，这可能会导致 Chrome 上的性能问题
          drop_console: true,
          // 生产环境去除 console
          drop_debugger: true
          // 生产环境去除 debugger
        }
      },
      chunkSizeWarningLimit: 2e3,
      // chunk 大小警告的限制（以 kbs 为单位）
      rollupOptions: {
        external: Object.keys(externalGlobalsObj),
        output: {
          chunkFileNames: `${dir}/js/chunk/[name]-[hash].js`,
          entryFileNames: `${dir}/js/entry/[name]-[hash].js`,
          assetFileNames: `${dir}/[ext]/[name]-[hash].[ext]`
        }
      }
    }
    /* css: {
      preprocessorOptions: {
        scss: {
          // ElementPlus自动导入定制化样式文件进行样式覆盖  @use "@/assets/styles/element.scss" as *;
          // 全局样式变量  @use "@/assets/styles/var.scss" as *;;
          additionalData: `
            @use "@/assets/styles/var.scss" as *;
          `,
        }
      }
    } */
  }
})
export { vite_config_default as default }
//# sourceMappingURL=data:application/json;base64,[encoded data, 9764 characters]
