This repository was archived by the owner on Aug 4, 2021. It is now read-only.
File tree 3 files changed +22
-2
lines changed
3 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ export interface Options {
85
85
* to prevent bundling the same package multiple times if package is
86
86
* imported from dependencies.
87
87
*/
88
- dedupe ?: string [ ] ;
88
+ dedupe ?: string [ ] | ( ( importee : string ) => boolean ) ;
89
89
90
90
/**
91
91
* Any additional options that should be passed through
Original file line number Diff line number Diff line change @@ -130,6 +130,10 @@ export default function nodeResolve ( options = {} ) {
130
130
const extensions = options . extensions || DEFAULT_EXTS ;
131
131
const packageInfoCache = new Map ( ) ;
132
132
133
+ const shouldDedupe = typeof dedupe === 'function'
134
+ ? dedupe
135
+ : importee => dedupe . includes ( importee ) ;
136
+
133
137
function getCachedPackageInfo ( pkg , pkgPath ) {
134
138
if ( packageInfoCache . has ( pkgPath ) ) {
135
139
return packageInfoCache . get ( pkgPath ) ;
@@ -216,7 +220,7 @@ export default function nodeResolve ( options = {} ) {
216
220
217
221
const basedir = importer ? dirname ( importer ) : process . cwd ( ) ;
218
222
219
- if ( dedupe . indexOf ( importee ) !== - 1 ) {
223
+ if ( shouldDedupe ( importee ) ) {
220
224
importee = join ( process . cwd ( ) , 'node_modules' , importee ) ;
221
225
}
222
226
Original file line number Diff line number Diff line change @@ -880,6 +880,22 @@ describe( 'rollup-plugin-node-resolve', function () {
880
880
} ) ;
881
881
} ) ;
882
882
883
+ it ( 'single module version is bundle if dedupe is set as a function' , ( ) => {
884
+ return rollup . rollup ( {
885
+ input : 'samples/react-app/main.js' ,
886
+ plugins : [
887
+ nodeResolve ( {
888
+ dedupe : ( dep ) => dep === 'react'
889
+ } )
890
+ ]
891
+ } ) . then ( executeBundle ) . then ( module => {
892
+ assert . deepEqual ( module . exports , {
893
+ React : 'react:root' ,
894
+ ReactConsumer : 'react-consumer:react:root'
895
+ } ) ;
896
+ } ) ;
897
+ } ) ;
898
+
883
899
it ( 'multiple module versions are bundled if dedupe is not set' , ( ) => {
884
900
return rollup . rollup ( {
885
901
input : 'samples/react-app/main.js' ,
You can’t perform that action at this time.
0 commit comments