@@ -19,14 +19,29 @@ const EXTERNAL_PATHS = [
1919 'echarts-for-react/lib/core' ,
2020 '/node_modules/echarts' ,
2121 '/node_modules/dayjs' ,
22- ] ;
23- const DEPENDENCIES = new Set ( Object . keys ( dependencies ) . concat ( Object . keys ( peerDependencies ) ) ) ;
24- const externals = ( id : string , importer : any , isResolved : boolean ) => {
22+ / ^ d a y j s \/ p l u g i n / ,
23+ / ^ d a y j s $ / ,
2524 // babel transforms module id of emotion, we need to exclude all of them
26- if ( id . startsWith ( '@emotion' ) ) {
27- return true ;
25+ / ^ @ e m o t i o n / ,
26+ ] ;
27+
28+ function shouldExternalize ( id : string ) {
29+ // check id against external paths
30+ for ( const path of EXTERNAL_PATHS ) {
31+ if ( typeof path === 'string' ) {
32+ if ( id . includes ( path ) ) {
33+ return true ;
34+ }
35+ } else if ( path . test ( id ) ) {
36+ return true ;
37+ }
2838 }
29- if ( EXTERNAL_PATHS . some ( ( p ) => id . includes ( p ) ) ) {
39+ return false ;
40+ }
41+
42+ const DEPENDENCIES = new Set ( Object . keys ( dependencies ) . concat ( Object . keys ( peerDependencies ) ) ) ;
43+ const externals = ( id : string ) => {
44+ if ( shouldExternalize ( id ) ) {
3045 return true ;
3146 }
3247 return DEPENDENCIES . has ( id ) ;
@@ -61,7 +76,6 @@ export default defineConfig({
6176 react : 'react' ,
6277 'react/jsx-runtime.js' : 'react/jsx-runtime.js' ,
6378 'reactflow/dist/style.css' : 'reactflow/dist/style.css' ,
64- 'dayjs/plugin' : 'dayjs/plugin' ,
6579 } ,
6680 } ,
6781 build : {
@@ -80,7 +94,9 @@ export default defineConfig({
8094 const ret = GLOBAL_MODULE_IDS [ name ] ;
8195 return ret ?? name ;
8296 }
83- const match = EXTERNAL_PATHS . find ( ( p ) => name . includes ( p ) ) ;
97+ const match = ( EXTERNAL_PATHS . filter ( ( it ) => typeof it === 'string' ) as string [ ] ) . find ( ( p ) =>
98+ name . includes ( p ) ,
99+ ) ;
84100 if ( match ) {
85101 return match . replace ( '/node_modules/' , '' ) ;
86102 }
0 commit comments