@@ -114,12 +114,30 @@ export function pnpPlugin({
114
114
115
115
const externals = parseExternals ( build . initialOptions . external ?? [ ] ) ;
116
116
117
- const isPlatformNode = ( build . initialOptions . platform ?? `browser` ) === `node` ;
117
+ const platform = build . initialOptions . platform ?? `browser` ;
118
+ const isPlatformNode = platform === `node` ;
119
+
120
+ // Reference: https://github.com/evanw/esbuild/blob/537195ae84bee1510fac14235906d588084c39cd/internal/resolver/resolver.go#L238-L253
121
+ const conditionsDefault = new Set ( build . initialOptions . conditions ) ;
122
+ conditionsDefault . add ( `default` ) ;
123
+ if ( platform === `browser` || platform === `node` )
124
+ conditionsDefault . add ( platform ) ;
125
+ const conditionsImport = new Set ( conditionsDefault ) ;
126
+ conditionsImport . add ( `import` ) ;
127
+ const conditionsRequire = new Set ( conditionsDefault ) ;
128
+ conditionsRequire . add ( `require` ) ;
118
129
119
130
build . onResolve ( { filter} , args => {
120
131
if ( isExternal ( args . path , externals ) )
121
132
return { external : true } ;
122
133
134
+ // Reference: https://github.com/evanw/esbuild/blob/537195ae84bee1510fac14235906d588084c39cd/internal/resolver/resolver.go#L1495-L1502
135
+ let conditions = conditionsDefault ;
136
+ if ( args . kind === `dynamic-import` || args . kind === `import-statement` )
137
+ conditions = conditionsImport ;
138
+ else if ( args . kind === `require-call` || args . kind === `require-resolve` )
139
+ conditions = conditionsRequire ;
140
+
123
141
// The entry point resolution uses an empty string
124
142
const effectiveImporter = args . importer
125
143
? args . importer
@@ -134,6 +152,7 @@ export function pnpPlugin({
134
152
let error ;
135
153
try {
136
154
path = pnpApi . resolveRequest ( args . path , effectiveImporter , {
155
+ conditions,
137
156
considerBuiltins : isPlatformNode ,
138
157
extensions,
139
158
} ) ;
0 commit comments