Nuxt/packages/cli/src/utils/cjs.ts

19 lines
430 B
TypeScript
Raw Normal View History

import { normalize } from 'upath'
export function resolveModule (id: string, paths?: string) {
return normalize(require.resolve(id, {
2021-04-15 19:17:44 +00:00
paths: [].concat(
// @ts-ignore
global.__NUXT_PREPATHS__,
paths,
process.cwd(),
// @ts-ignore
global.__NUXT_PATHS__
).filter(Boolean)
}))
2021-04-15 19:17:44 +00:00
}
export function requireModule (id: string, paths?: string) {
2021-04-15 19:17:44 +00:00
return require(resolveModule(id, paths))
}