@@ -20,7 +20,7 @@ import { dirname, join, normalize, resolve } from "pathe";
2020import type { Plugin } from "rollup" ;
2121import { visualizer } from "rollup-plugin-visualizer" ;
2222import { isTest , isWindows } from "std-env" ;
23- import * as unenv from "unenv" ;
23+ import { defineEnv } from "unenv" ;
2424import type { Preset } from "unenv" ;
2525import unimportPlugin from "unimport/unplugin" ;
2626import { rollup as unwasm } from "unwasm/plugin" ;
@@ -54,27 +54,46 @@ export const getRollupConfig = (nitro: Nitro): RollupConfig => {
5454 ".jsx" ,
5555 ] ;
5656
57- const nodePreset = nitro . options . node === false ? unenv . nodeless : unenv . node ;
58-
59- const builtinPreset : Preset = {
60- alias : {
61- // General
62- ...( nitro . options . dev
63- ? { }
64- : {
65- debug : "unenv/npm/debug" ,
66- } ) ,
67- ...( nitro . options . node === false
68- ? { }
69- : {
70- "node-mock-http/_polyfill/events" : "node:events" ,
71- "node-mock-http/_polyfill/buffer" : "node:buffer" ,
72- } ) ,
73- ...nitro . options . alias ,
57+ const isNodeless = nitro . options . node === false ;
58+
59+ const { env } = defineEnv ( {
60+ nodeCompat : isNodeless ,
61+ resolve : true ,
62+ presets : [
63+ isNodeless
64+ ? {
65+ // Backward compatibility (remove in v2)
66+ // https://github.com/unjs/unenv/pull/427
67+ inject : {
68+ performance : "unenv/polyfill/performance" ,
69+ } ,
70+ polyfill : [
71+ "unenv/polyfill/globalthis-global" ,
72+ "unenv/polyfill/process" ,
73+ "unenv/polyfill/performance" ,
74+ ] ,
75+ }
76+ : { } ,
77+ nitro . options . unenv ,
78+ ] ,
79+ overrides : {
80+ alias : {
81+ // General
82+ ...( nitro . options . dev
83+ ? { }
84+ : {
85+ debug : "unenv/npm/debug" ,
86+ } ) ,
87+ ...( isNodeless
88+ ? { }
89+ : {
90+ "node-mock-http/_polyfill/events" : "node:events" ,
91+ "node-mock-http/_polyfill/buffer" : "node:buffer" ,
92+ } ) ,
93+ ...nitro . options . alias ,
94+ } ,
7495 } ,
75- } ;
76-
77- const env = unenv . env ( nodePreset , builtinPreset , nitro . options . unenv ) ;
96+ } ) ;
7897
7998 const buildServerDir = join ( nitro . options . buildDir , "dist/server" ) ;
8099
0 commit comments