Newer
Older
gnexus-tasks / extension / vite.config.ts
import { cpSync, existsSync } from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

const here = fileURLToPath(new URL('.', import.meta.url))

// kit.css ссылается на шрифты/иконки через абсолютные /assets/... URL —
// в расширении они резолвятся в chrome-extension://<id>/assets/...,
// поэтому dist кита копируется в dist/assets при сборке (как во фронте).
const kitAssetsDir = path.resolve(here, 'node_modules/gnexus-ui-kit/dist/assets')

function kitAssetsPlugin() {
  return {
    name: 'gnexus-kit-assets',
    closeBundle() {
      if (!existsSync(kitAssetsDir)) return
      const dest = path.resolve(here, 'dist/assets')
      cpSync(kitAssetsDir, dest, { recursive: true })
    },
  }
}

export default defineConfig({
  plugins: [vue(), kitAssetsPlugin()],
  build: {
    outDir: 'dist',
    emptyOutDir: true,
    rollupOptions: {
      input: path.resolve(here, 'popup.html'),
    },
  },
})