N
Nuxt5mo ago
∂Max

Support of the new URL(..., import.meta.url) syntax?

Hey guys, I wanted to know if nuxt.js supports the new URL(..., import.meta.url) syntax. If there's none at the moment, can you tell me how I can help add it? This is a big blocker for an education project at the moment (I cannot fully use monaco-editor-wrapper).
3 Replies
∂Max
∂MaxOP5mo ago
I tried using an esbuild plugin but sadly it looks like it didn't work with nuxt.js (with react and vite it does)
import importMetaUrlPlugin from '@codingame/esbuild-import-meta-url-plugin'

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
devtools: { enabled: true },
ssr: false,
vite: {
optimizeDeps: {
esbuildOptions: {
plugins: [importMetaUrlPlugin]
}
}
}
})
import importMetaUrlPlugin from '@codingame/esbuild-import-meta-url-plugin'

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
devtools: { enabled: true },
ssr: false,
vite: {
optimizeDeps: {
esbuildOptions: {
plugins: [importMetaUrlPlugin]
}
}
}
})
It works as intended without nuxt, but with nuxt it doesn't have any effect
Hendrik Jan
Hendrik Jan5mo ago
I'm not sure if this will help you, but for me it seems to work in nuxt.config.js in runtimeConfig:
// nuxt.config.js
export default defineNuxtConfig({
rootDir: new URL('./', import.meta.url).pathname,

runtimeConfig: {
rootDir: new URL('./', import.meta.url).pathname,
}
})
// nuxt.config.js
export default defineNuxtConfig({
rootDir: new URL('./', import.meta.url).pathname,

runtimeConfig: {
rootDir: new URL('./', import.meta.url).pathname,
}
})
And then somewhere else use it like:
// server/api/v1/changelog/index.get.ts
export default defineEventHandler(async (event) => {
const config = useRuntimeConfig();
const changelog = fs.readFileSync(config.rootDir + '/CHANGELOG.md', 'utf8');
})
// server/api/v1/changelog/index.get.ts
export default defineEventHandler(async (event) => {
const config = useRuntimeConfig();
const changelog = fs.readFileSync(config.rootDir + '/CHANGELOG.md', 'utf8');
})
∂Max
∂MaxOP5mo ago
Thanks! I’ll take a look tomorrow
Want results from more Discord servers?
Add your server