Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
| import path from 'path' | |
| const localNodeModules = path.resolve(process.cwd(), 'node_modules') | |
| // Prefer importing modules from local node_modules (for NPX and global bin) | |
| async function _import(modulePath) { | |
| for (const mp of [ | |
| path.resolve(localNodeModules, modulePath), | |
| modulePath | |
| ]) { | |
| try { | |
| return await import(mp) | |
| } catch (e) { | |
| if (e.code !== 'MODULE_NOT_FOUND') { | |
| throw e | |
| } | |
| } | |
| } | |
| const error = new Error(`Cannot import module '${modulePath}'`) | |
| error.code = 'MODULE_NOT_FOUND' | |
| throw error | |
| } | |
| export const builder = () => _import('@nuxt/builder') | |
| export const webpack = () => _import('@nuxt/webpack') | |
| export const generator = () => _import('@nuxt/generator') | |
| export const core = () => _import('@nuxt/core') | |
| export const tsNode = () => _import('ts-node') | |
| export const nuxtTypescript = () => _import('@nuxt/typescript') | |
| export const importModule = _import |