File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,39 @@ import glob from 'glob';
4
4
import path from 'path' ;
5
5
import pkgUp from 'pkg-up' ;
6
6
7
+ /**
8
+ * Guarantees that any files imported from a peer dependency are treated as an external.
9
+ *
10
+ * For example, if we import `chart.js/auto`, that would not normally
11
+ * match the "chart.js" we pass to the "externals" config. This plugin
12
+ * catches that case and adds it as an external.
13
+ *
14
+ * Inspired by https://github.com/oat-sa/rollup-plugin-wildcard-external
15
+ */
16
+ const wildcardExternalsPlugin = ( peerDependencies ) => ( {
17
+ name : 'wildcard-externals' ,
18
+ resolveId ( source , importer ) {
19
+ if ( importer ) {
20
+ let matchesExternal = false ;
21
+ peerDependencies . forEach ( ( peerDependency ) => {
22
+ if ( source . includes ( `/${ peerDependency } /` ) ) {
23
+ matchesExternal = true ;
24
+ }
25
+ } ) ;
26
+
27
+ if ( matchesExternal ) {
28
+ return {
29
+ id : source ,
30
+ external : true ,
31
+ moduleSideEffects : true
32
+ } ;
33
+ }
34
+ }
35
+
36
+ return null ; // other ids should be handled as usually
37
+ }
38
+ } ) ;
39
+
7
40
const files = glob . sync ( "src/**/assets/src/*controller.ts" ) ;
8
41
const packages = files . map ( ( file ) => {
9
42
const absolutePath = path . join ( __dirname , file ) ;
@@ -23,6 +56,7 @@ const packages = files.map((file) => {
23
56
plugins : [
24
57
resolve ( ) ,
25
58
typescript ( ) ,
59
+ wildcardExternalsPlugin ( peerDependencies )
26
60
] ,
27
61
} ;
28
62
} ) ;
You can’t perform that action at this time.
0 commit comments