File tree Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,8 @@ module.exports = {
2020 new CircularDependencyPlugin ({
2121 // exclude detection of files based on a RegExp
2222 exclude: / a\. js| node_modules/ ,
23+ // include specific files based on a RegExp
24+ include: / dir/ ,
2325 // add errors to webpack instead of warnings
2426 failOnError: true ,
2527 // allow import cycles that include an asyncronous import,
Original file line number Diff line number Diff line change @@ -96,6 +96,28 @@ describe('circular dependency', () => {
9696 expect ( stats . warnings [ 1 ] ) . toMatch ( / g \. j s / )
9797 } )
9898
99+ it ( 'can include only specific cyclical deps in the output' , async ( ) => {
100+ let fs = new MemoryFS ( )
101+ let compiler = webpack ( {
102+ mode : 'development' ,
103+ entry : path . join ( __dirname , 'deps/d.js' ) ,
104+ output : { path : __dirname } ,
105+ plugins : [
106+ new CircularDependencyPlugin ( {
107+ include : / f \. j s /
108+ } )
109+ ]
110+ } )
111+ compiler . outputFileSystem = fs
112+
113+ let runAsync = wrapRun ( compiler . run . bind ( compiler ) )
114+ let stats = await runAsync ( )
115+ stats . warnings . forEach ( warning => {
116+ const firstFile = warning . match ( / \w + \. j s / ) [ 0 ]
117+ expect ( firstFile ) . toMatch ( / f \. j s / )
118+ } )
119+ } )
120+
99121 it ( `can handle context modules that have an undefined resource h -> i -> a -> i` , async ( ) => {
100122 let fs = new MemoryFS ( )
101123 let compiler = webpack ( {
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ class CircularDependencyPlugin {
77 constructor ( options ) {
88 this . options = extend ( {
99 exclude : new RegExp ( '$^' ) ,
10+ include : new RegExp ( '.*' ) ,
1011 failOnError : false ,
1112 allowAsyncCycles : false ,
1213 onDetected : false ,
@@ -26,7 +27,8 @@ class CircularDependencyPlugin {
2627 for ( let module of modules ) {
2728 const shouldSkip = (
2829 module . resource == null ||
29- plugin . options . exclude . test ( module . resource )
30+ plugin . options . exclude . test ( module . resource ) ||
31+ ! plugin . options . include . test ( module . resource )
3032 )
3133 // skip the module if it matches the exclude pattern
3234 if ( shouldSkip ) {
You can’t perform that action at this time.
0 commit comments