@@ -17,36 +17,38 @@ const escapeRegexSpecialChars = (inputString: string): string => {
17
17
return inputString . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, '\\$&' ) ; // $& means the whole matched string
18
18
} ;
19
19
20
- export const createRemoveIdPrefixPlugin = ( externals : string [ ] ) : Plugin => ( {
21
- name : 'vite-plugin-remove-id-prefix' ,
22
- apply : 'serve' ,
23
- configResolved : ( resolvedConfig ) => {
24
- // don't do anything when the list of externals is empty
25
- if ( externals . length === 0 ) {
26
- return ;
27
- }
28
-
29
- const escapedExternals = externals . map ( escapeRegexSpecialChars ) ;
30
- const prefixedExternalRegex = new RegExp (
31
- `${ VITE_ID_PREFIX } (${ escapedExternals . join ( '|' ) } )` ,
32
- 'g' ,
33
- ) ;
34
-
35
- // @ts -expect-error: Property 'push' does not exist on type 'readonly Plugin<any>[]'
36
- // Reasoning:
37
- // since the /@id / prefix is added by Vite's import-analysis plugin,
38
- // we must add our actual plugin dynamically, to ensure that it will run
39
- // AFTER the import-analysis.
40
- resolvedConfig . plugins . push ( {
41
- name : 'vite-plugin-remove-id-prefix-transform' ,
42
- transform : ( code : string ) => {
43
- // don't do anything when code does not contain the Vite prefix
44
- if ( ! code . includes ( VITE_ID_PREFIX ) ) {
45
- return code ;
46
- }
47
-
48
- return code . replace ( prefixedExternalRegex , ( _ , externalName ) => externalName ) ;
49
- } ,
50
- } ) ;
51
- } ,
52
- } ) ;
20
+ export function createRemoveIdPrefixPlugin ( externals : string [ ] ) : Plugin {
21
+ return {
22
+ name : 'angular-plugin-remove-id-prefix' ,
23
+ apply : 'serve' ,
24
+ configResolved : ( resolvedConfig ) => {
25
+ // don't do anything when the list of externals is empty
26
+ if ( externals . length === 0 ) {
27
+ return ;
28
+ }
29
+
30
+ const escapedExternals = externals . map ( escapeRegexSpecialChars ) ;
31
+ const prefixedExternalRegex = new RegExp (
32
+ `${ VITE_ID_PREFIX } (${ escapedExternals . join ( '|' ) } )` ,
33
+ 'g' ,
34
+ ) ;
35
+
36
+ // @ts -expect-error: Property 'push' does not exist on type 'readonly Plugin<any>[]'
37
+ // Reasoning:
38
+ // since the /@id / prefix is added by Vite's import-analysis plugin,
39
+ // we must add our actual plugin dynamically, to ensure that it will run
40
+ // AFTER the import-analysis.
41
+ resolvedConfig . plugins . push ( {
42
+ name : 'angular-plugin-remove-id-prefix-transform' ,
43
+ transform : ( code : string ) => {
44
+ // don't do anything when code does not contain the Vite prefix
45
+ if ( ! code . includes ( VITE_ID_PREFIX ) ) {
46
+ return code ;
47
+ }
48
+
49
+ return code . replace ( prefixedExternalRegex , ( _ , externalName ) => externalName ) ;
50
+ } ,
51
+ } ) ;
52
+ } ,
53
+ } ;
54
+ }
0 commit comments