Skip to content

Commit

Permalink
fix(dev): support .config/ dir and custom config extensions (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 14, 2024
1 parent a78c5e6 commit 19c3aa0
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/utils/dev.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { RequestListener, ServerResponse } from 'node:http'
import EventEmitter from 'node:events'
import { relative, resolve } from 'pathe'
import { relative, resolve, join } from 'pathe'
import chokidar from 'chokidar'
import { consola } from 'consola'
import { debounce } from 'perfect-debounce'
Expand Down Expand Up @@ -77,7 +77,9 @@ export async function createNuxtDevServer(
return devServer
}

const RESTART_RE = /^(nuxt\.config\.(js|ts|mjs|cjs)|\.nuxtignore|\.nuxtrc)$/
// https://regex101.com/r/7HkR5c/1
const RESTART_RE =
/^(nuxt\.config\.[a-z0-9]+|\.nuxtignore|\.nuxtrc|\.config\/nuxt(\.config)?\.[a-z0-9]+)$/

class NuxtDevServer extends EventEmitter {
private _handler?: RequestListener
Expand Down Expand Up @@ -281,10 +283,13 @@ class NuxtDevServer extends EventEmitter {
}

async _watchConfig() {
const configWatcher = chokidar.watch([this.options.cwd], {
ignoreInitial: true,
depth: 0,
})
const configWatcher = chokidar.watch(
[this.options.cwd, join(this.options.cwd, '.config')],
{
ignoreInitial: true,
depth: 0,
},
)
configWatcher.on('all', (_event, _file) => {
const file = relative(this.options.cwd, _file)
if (file === (this.options.dotenv || '.env')) {
Expand Down

0 comments on commit 19c3aa0

Please sign in to comment.