Skip to content

vite separate config file resolve problem #4460

Closed
@orangzz

Description

@orangzz

Describe the bug

separate vite config file is not resolve as expected

Reproduction

// .vitepress/config.ts

export default defineConfig({
  srcDir: 'content',
  base: BASE_PATH,
  outDir: 'dist',
  cacheDir: 'cache',
  markdown: {
    config: (md) => {
      md.use(groupIconMdPlugin)
    }
  },
  themeConfig: {
    // theme-level options
  }
})

running DEBUG=vite:config,vite:resolve,vite:debug-alias vitepress dev

debug info showing vitepress config as expect

  vite:config   vitepress: {
  vite:config     root: '/Users/ayao/repos/vita-ui/packages/docs',
  vite:config     srcDir: '/Users/ayao/repos/vita-ui/packages/docs/content',

but separate vite config is not respect(i expect it to be /Users/ayao/repos/vita-ui/packages/docs`

which is where the script is running and the separate config file vite.config.ts root field is config like that
root: __dirname,

  vite:config bundled config file loaded in 34.09ms +0ms
  vite:config no config file found. +53ms
  vite:config using resolved config: {
  vite:config   root: '/Users/ayao/repos/vita-ui/packages/docs/content',
  vite:config   base: '/wiki/',
  vite:config   cacheDir: '/Users/ayao/repos/vita-ui/packages/docs/cache',
  vite:config   plugins: [

my viteconfig as following

import { defineConfig, createLogger } from 'vite'
import path, { resolve } from 'path'
import { fileURLToPath } from 'node:url'

import Components from 'unplugin-vue-components/vite'
import AutoImport from 'unplugin-auto-import/vite'
import Inspect from 'vite-plugin-inspect'
import { groupIconVitePlugin, localIconLoader } from 'vitepress-plugin-group-icons'


const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const logger = createLogger();

export default defineConfig({
  optimizeDeps: {
    exclude: [
      'vitepress',
    ],
  },
  logLevel: 'info',
  clearScreen: false,
  resolve: {
    alias: {
      "@utils": resolve(__dirname, "./utils"),
      "@": resolve(__dirname, "./content"),
      "@oss": resolve(__dirname, "./oss"),
    }
  },
  plugins: [
    {
      name: 'vite:debug-alias',
      configResolved(config) {
        debugger
        logger.info(`Alias config: ${JSON.stringify(config.resolve.alias)}`);
      },
      resolveId(id) {
        if (id.startsWith('@utils')) {
          logger.info(`Resolving @utils path: ${id}`);
        }
      },
    },
    Inspect({
      build: true,
      dev: true,
      outputDir: '.vite-inspect',
    }),
    Components({
      dirs: [
        "components",
      ],
      include: [
        /\.vue$/,
        /\.vue\?vue/,
      ],
      dts: "components.d.ts"
    }),
    AutoImport({
      imports: ["vue", "@vueuse/core"],
      dirs: ["composables"],
      vueTemplate: true,
      dts: "auto-imports.d.ts"
    }),
    groupIconVitePlugin({
      customIcon: {
        'docker': 'vscode-icons:file-type-docker2',
        'k8s': localIconLoader(import.meta.url, './assets/devicon--kubernetes.svg'),
        'dir': localIconLoader(import.meta.url, './assets/mingcute--directory-line.svg'),
        'bnf': localIconLoader(import.meta.url, './assets/file-icons--bnf.svg'),
      },
    }),

  ],
})

Expected behavior

all my plugin didn't register in merge config

 plugins: [
  vite:config     'vite:optimized-deps',
  vite:config     'vite:watch-package-data',
  vite:config     'vite:pre-alias',
,,,
 ]
 ~  tree -L 2
├── content
│   └── index.md
├── logs
│   └── debug.log
└── vite.config.ts
├── .vitepress
│   └── config.ts

one thing to know that the separte vite config is respect if config srcDir to cwd(meaning leaving empty with default)
the separate vite config will be respect and all the plugin is register successfully
but i prefer flat structure, wish to pull all my markdown file in content direcotry, so i was hoping this issue could be resolve

System Info

~  npx envinfo --system --npmPackages vitepress --binaries --browsers

  System:
    OS: macOS 14.4
    CPU: (8) arm64 Apple M1
    Memory: 90.00 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.18.1 - ~/n/bin/node
    npm: 10.8.2 - ~/n/bin/npm
    pnpm: 9.15.2 - ~/n/bin/pnpm
    Watchman: 2024.12.02.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome Canary: 133.0.6933.0
    Safari: 17.4
  npmPackages:
    vitepress: catalog: => 1.5.0

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions