Skip to content

Commit b317687

Browse files
committed
feat(hmr): add alias resolution to rollup configuration
1 parent ec560bb commit b317687

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/utils/hmr.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { WebSocket } from 'ws'
66
import type { NuxtDiscordContext } from '../types'
77
import fs from 'node:fs'
88
import path from 'node:path'
9-
import { addVitePlugin, isIgnored, updateTemplates } from '@nuxt/kit'
9+
import { addVitePlugin, isIgnored, resolveAlias, updateTemplates } from '@nuxt/kit'
1010
import chokidar from 'chokidar'
1111
import { listen } from 'listhen'
1212
import { rollup } from 'rollup'
@@ -52,6 +52,7 @@ export function prepareHMR(ctx: NuxtDiscordContext) {
5252
...nitroConfig.hooks,
5353
'rollup:before': (nitroCtx, config) => {
5454
originalBeforeHook?.(nitroCtx, config)
55+
// TODO: might need to merge with user nuxt config.server.rollupConfig.plugins
5556
config.plugins = [
5657
config.plugins,
5758
TransformPlugin(ctx),
@@ -247,8 +248,18 @@ async function generateDynamicCommandBuild(file: string, config: RollupConfig, c
247248
bundle = await rollup({
248249
...config,
249250
input: file,
250-
// externalize all modules except the command file itself, excluding .ts files
251-
external: id => !id.includes(file) && !id.endsWith('.ts'),
251+
plugins: [
252+
config.plugins,
253+
{
254+
name: 'discord:resolve-alias-and-externalize',
255+
resolveId: (id) => {
256+
// externalize all modules except the command file itself, excluding .ts files
257+
if (!id.includes(file) && !id.endsWith('.ts')) {
258+
return { id: resolveAlias(id), external: true }
259+
}
260+
},
261+
},
262+
],
252263
})
253264
const { output } = await bundle.generate({ ...config.output, sourcemap: false })
254265
fs.mkdirSync(path.join(ctx.nuxt.options.buildDir, 'discord', 'commands'), { recursive: true })

0 commit comments

Comments
 (0)