@@ -456,16 +456,24 @@ Conditional exports can also be extended to exports subpaths, for example:
456
456
" exports" : {
457
457
" ." : " ./main.js" ,
458
458
" ./feature" : {
459
- " browser " : " ./feature-browser .js" ,
459
+ " node " : " ./feature-node .js" ,
460
460
" default" : " ./feature.js"
461
461
}
462
462
}
463
463
}
464
464
```
465
465
466
466
Defines a package where ` require('pkg/feature') ` and ` import 'pkg/feature' `
467
- could provide different implementations between the browser and Node.js,
468
- given third-party tool support for a ` "browser" ` condition.
467
+ could provide different implementations between Node.js and other JS
468
+ environments.
469
+
470
+ When using environment branches, always include a ` "default" ` condition where
471
+ possible. Providing a ` "default" ` condition ensures that any unknown JS
472
+ environments are able to use this universal implementation, which helps avoid
473
+ these JS environments from having to pretend to be existing environments in
474
+ order to support packages with conditional exports. For this reason, using
475
+ ` "node" ` and ` "default" ` condition branches is usually preferable to using
476
+ ` "node" ` and ` "browser" ` condition branches.
469
477
470
478
#### Nested conditions
471
479
@@ -479,11 +487,11 @@ use in Node.js but not the browser:
479
487
{
480
488
" main" : " ./main.js" ,
481
489
" exports" : {
482
- " browser" : " ./feature-browser.mjs" ,
483
490
" node" : {
484
491
" import" : " ./feature-node.mjs" ,
485
492
" require" : " ./feature-node.cjs"
486
- }
493
+ },
494
+ " default" : " ./feature.mjs" ,
487
495
}
488
496
}
489
497
```
0 commit comments