mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-14 10:04:05 +00:00
fix(nuxt3): use ts-friendly paths for global imports (#662)
This commit is contained in:
parent
baa4ddbae0
commit
ae0dbda2ce
@ -1,5 +1,5 @@
|
|||||||
import { addVitePlugin, addWebpackPlugin, defineNuxtModule, addTemplate, resolveAlias, addPluginTemplate } from '@nuxt/kit'
|
import { addVitePlugin, addWebpackPlugin, defineNuxtModule, addTemplate, resolveAlias, addPluginTemplate } from '@nuxt/kit'
|
||||||
import { resolve } from 'pathe'
|
import { isAbsolute, relative, resolve } from 'pathe'
|
||||||
import type { Identifiers, GlobalImportsOptions } from './types'
|
import type { Identifiers, GlobalImportsOptions } from './types'
|
||||||
import { TransformPlugin } from './transform'
|
import { TransformPlugin } from './transform'
|
||||||
import { defaultIdentifiers } from './identifiers'
|
import { defaultIdentifiers } from './identifiers'
|
||||||
@ -31,7 +31,17 @@ export default defineNuxtModule<GlobalImportsOptions>({
|
|||||||
|
|
||||||
// Add types
|
// Add types
|
||||||
const resolved = {}
|
const resolved = {}
|
||||||
const r = id => resolved[id] || (resolved[id] = resolveAlias(id, nuxt.options.alias))
|
const r = (id: string) => {
|
||||||
|
if (resolved[id]) { return resolved[id] }
|
||||||
|
let path = resolveAlias(id, nuxt.options.alias)
|
||||||
|
if (isAbsolute(path)) {
|
||||||
|
path = relative(nuxt.options.buildDir, path)
|
||||||
|
}
|
||||||
|
// Remove file extension for benefit of TypeScript
|
||||||
|
path = path.replace(/\.[a-z]+$/, '')
|
||||||
|
resolved[id] = path
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
|
||||||
addTemplate({
|
addTemplate({
|
||||||
filename: 'global-imports.d.ts',
|
filename: 'global-imports.d.ts',
|
||||||
|
Loading…
Reference in New Issue
Block a user