@@ -26,23 +26,31 @@ function insertText(str, dir, preprocessor = res => res, processFilename = false
26
26
}
27
27
28
28
export default function angular ( options = { } ) {
29
- options . preprocessors = options . preprocessors || { } ;
29
+ options . preprocessors = options . preprocessors || { } ; // set default preprocessors to `{}`
30
+ options . replace = ( typeof options . replace === 'boolean' ) ? options . replace : true ; // set default replace to `true`
30
31
31
32
// ignore @angular /** modules
32
33
options . exclude = options . exclude || [ ] ;
33
- if ( typeof options . exclude === 'string' || options . exclude instanceof String ) options . exclude = [ options . exclude ] ;
34
- if ( options . exclude . indexOf ( 'node_modules/@angular/**' ) === - 1 ) options . exclude . push ( 'node_modules/@angular/**' ) ;
34
+ if ( typeof options . exclude === 'string' || options . exclude instanceof String ) {
35
+ options . exclude = [ options . exclude ] ;
36
+ }
37
+ if ( options . exclude . indexOf ( 'node_modules/@angular/**' ) === - 1 ) {
38
+ options . exclude . push ( 'node_modules/@angular/**' ) ;
39
+ }
35
40
36
41
const filter = createFilter ( options . include , options . exclude ) ;
37
42
38
43
return {
39
44
name : 'angular' ,
40
45
transform ( source , map ) {
41
46
if ( ! filter ( map ) ) return ;
47
+ // replace comments in source
42
48
source = source . replace ( commentRegex , '' ) ;
49
+ // use MagicString
43
50
const magicString = new MagicString ( source ) ;
44
-
51
+ // get dir from `map`
45
52
const dir = path . parse ( map ) . dir ;
53
+ // get file extension from `map`
46
54
const fileExt = map . split ( '.' ) . pop ( ) ;
47
55
48
56
let hasReplacements = false ;
@@ -57,7 +65,7 @@ export default function angular(options = {}) {
57
65
. replace ( templateUrlRegex , function ( match , url ) {
58
66
hasReplacements = true ;
59
67
const toReplace = 'template:' + insertText ( url , dir , options . preprocessors . template , options . processFilename , options . sourcetype ) ;
60
- if ( fileExt === 'js' ) {
68
+ if ( fileExt === 'js' && options . replace === true ) {
61
69
/* replace templateUrl in files generated by ngc */
62
70
replace ( {
63
71
regex : match ,
@@ -74,7 +82,7 @@ export default function angular(options = {}) {
74
82
hasReplacements = true ;
75
83
const toReplace = 'styles:' + insertText ( urls , dir , options . preprocessors . style , options . processFilename , options . sourcetype ) ;
76
84
/* replace styles in files generated by ngc */
77
- if ( fileExt === 'js' ) {
85
+ if ( fileExt === 'js' && options . replace === true ) {
78
86
replace ( {
79
87
regex : styleUrlsRegex ,
80
88
replacement : toReplace ,
0 commit comments