mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-13 09:33:54 +00:00
fix(vite): correctly import node builtins in dev bundler (#2753)
This commit is contained in:
parent
2ba5f56374
commit
4b351504e8
@ -1,5 +1,6 @@
|
|||||||
import { pathToFileURL } from 'url'
|
import { pathToFileURL } from 'url'
|
||||||
import { existsSync } from 'fs'
|
import { existsSync } from 'fs'
|
||||||
|
import { builtinModules } from 'module'
|
||||||
import { resolve } from 'pathe'
|
import { resolve } from 'pathe'
|
||||||
import * as vite from 'vite'
|
import * as vite from 'vite'
|
||||||
import { ExternalsOptions, isExternal as _isExternal, ExternalsDefaults } from 'externality'
|
import { ExternalsOptions, isExternal as _isExternal, ExternalsDefaults } from 'externality'
|
||||||
@ -73,8 +74,11 @@ async function transformRequest (opts: TransformOptions, id: string) {
|
|||||||
// Remove for externals
|
// Remove for externals
|
||||||
const withoutVersionQuery = id.replace(/\?v=\w+$/, '')
|
const withoutVersionQuery = id.replace(/\?v=\w+$/, '')
|
||||||
if (await isExternal(opts, withoutVersionQuery)) {
|
if (await isExternal(opts, withoutVersionQuery)) {
|
||||||
|
const path = builtinModules.includes(withoutVersionQuery.split('node:').pop())
|
||||||
|
? withoutVersionQuery
|
||||||
|
: pathToFileURL(withoutVersionQuery)
|
||||||
return {
|
return {
|
||||||
code: `(global, exports, importMeta, ssrImport, ssrDynamicImport, ssrExportAll) => import('${(pathToFileURL(withoutVersionQuery))}').then(r => { exports.default = r.default; ssrExportAll(r) }).catch(e => { console.error(e); throw new Error('[vite dev] Error loading external "${id}".') })`,
|
code: `(global, exports, importMeta, ssrImport, ssrDynamicImport, ssrExportAll) => import('${path}').then(r => { exports.default = r.default; ssrExportAll(r) }).catch(e => { console.error(e); throw new Error('[vite dev] Error loading external "${id}".') })`,
|
||||||
deps: [],
|
deps: [],
|
||||||
dynamicDeps: []
|
dynamicDeps: []
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user