1
- import * as fs from 'fs' ;
2
1
import { ng } from '../../utils/process' ;
3
2
import {
4
3
expectFileToMatch ,
5
4
expectFileToExist ,
6
5
expectFileMatchToExist ,
7
6
writeMultipleFiles
8
7
} from '../../utils/fs' ;
8
+ import { copyProjectAsset } from '../../utils/assets' ;
9
9
import { expectToFail } from '../../utils/utils' ;
10
10
import { getGlobalVariable } from '../../utils/env' ;
11
11
@@ -26,32 +26,34 @@ export default function () {
26
26
. then ( ( ) => writeMultipleFiles ( {
27
27
'src/styles.css' : `
28
28
h1 { background: url('/assets/global-img-absolute.svg'); }
29
- h2 { background: url('./assets/global-img-relative.svg '); }
29
+ h2 { background: url('./assets/global-img-relative.png '); }
30
30
` ,
31
31
'src/app/app.component.css' : `
32
32
h3 { background: url('/assets/component-img-absolute.svg'); }
33
- h4 { background: url('../assets/component-img-relative.svg '); }
33
+ h4 { background: url('../assets/component-img-relative.png '); }
34
34
` ,
35
- // Using SVGs because they are loaded via file-loader and thus never inlined.
36
35
'src/assets/global-img-absolute.svg' : imgSvg ,
37
- 'src/assets/global-img-relative.svg' : imgSvg ,
38
- 'src/assets/component-img-absolute.svg' : imgSvg ,
39
- 'src/assets/component-img-relative.svg' : imgSvg
36
+ 'src/assets/component-img-absolute.svg' : imgSvg
40
37
} ) )
38
+ // use image with file size >10KB to prevent inlining
39
+ . then ( ( ) => copyProjectAsset ( 'images/spectrum.png' , './assets/global-img-relative.png' ) )
40
+ . then ( ( ) => copyProjectAsset ( 'images/spectrum.png' , './assets/component-img-relative.png' ) )
41
41
. then ( ( ) => ng ( 'build' , '--extract-css' , '--aot' ) )
42
42
// Check paths are correctly generated.
43
43
. then ( ( ) => expectFileToMatch ( 'dist/styles.bundle.css' , '/assets/global-img-absolute.svg' ) )
44
44
. then ( ( ) => expectFileToMatch ( 'dist/styles.bundle.css' ,
45
- / g l o b a l - i m g - r e l a t i v e \. [ 0 - 9 a - f ] { 20 } \. s v g / ) )
45
+ / u r l \( ' \/ a s s e t s \/ g l o b a l - i m g - a b s o l u t e \. s v g ' \) / ) )
46
+ . then ( ( ) => expectFileToMatch ( 'dist/styles.bundle.css' ,
47
+ / g l o b a l - i m g - r e l a t i v e \. [ 0 - 9 a - f ] { 20 } \. p n g / ) )
46
48
. then ( ( ) => expectFileToMatch ( 'dist/main.bundle.js' ,
47
49
'/assets/component-img-absolute.svg' ) )
48
50
. then ( ( ) => expectFileToMatch ( 'dist/main.bundle.js' ,
49
- / c o m p o n e n t - i m g - r e l a t i v e \. [ 0 - 9 a - f ] { 20 } \. s v g / ) )
51
+ / c o m p o n e n t - i m g - r e l a t i v e \. [ 0 - 9 a - f ] { 20 } \. p n g / ) )
50
52
// Check files are correctly created.
51
53
. then ( ( ) => expectToFail ( ( ) => expectFileToExist ( 'dist/global-img-absolute.svg' ) ) )
52
54
. then ( ( ) => expectToFail ( ( ) => expectFileToExist ( 'dist/component-img-absolute.svg' ) ) )
53
- . then ( ( ) => expectFileMatchToExist ( './dist' , / g l o b a l - i m g - r e l a t i v e \. [ 0 - 9 a - f ] { 20 } \. s v g / ) )
54
- . then ( ( ) => expectFileMatchToExist ( './dist' , / c o m p o n e n t - i m g - r e l a t i v e \. [ 0 - 9 a - f ] { 20 } \. s v g / ) )
55
+ . then ( ( ) => expectFileMatchToExist ( './dist' , / g l o b a l - i m g - r e l a t i v e \. [ 0 - 9 a - f ] { 20 } \. p n g / ) )
56
+ . then ( ( ) => expectFileMatchToExist ( './dist' , / c o m p o n e n t - i m g - r e l a t i v e \. [ 0 - 9 a - f ] { 20 } \. p n g / ) )
55
57
// Check urls with deploy-url scheme are used as is.
56
58
. then ( ( ) => ng ( 'build' , '--base-href=/base/' , '--deploy-url=http://deploy.url/' ,
57
59
'--extract-css' ) )
@@ -79,9 +81,9 @@ export default function () {
79
81
. then ( ( ) => expectFileToMatch ( 'dist/styles.bundle.css' ,
80
82
'/base/deploy/assets/global-img-absolute.svg' ) )
81
83
. then ( ( ) => expectFileToMatch ( 'dist/styles.bundle.css' ,
82
- / g l o b a l - i m g - r e l a t i v e \. [ 0 - 9 a - f ] { 20 } \. s v g / ) )
84
+ / g l o b a l - i m g - r e l a t i v e \. [ 0 - 9 a - f ] { 20 } \. p n g / ) )
83
85
. then ( ( ) => expectFileToMatch ( 'dist/main.bundle.js' ,
84
86
'/base/deploy/assets/component-img-absolute.svg' ) )
85
87
. then ( ( ) => expectFileToMatch ( 'dist/main.bundle.js' ,
86
- / d e p l o y \/ c o m p o n e n t - i m g - r e l a t i v e \. [ 0 - 9 a - f ] { 20 } \. s v g / ) ) ;
88
+ / d e p l o y \/ c o m p o n e n t - i m g - r e l a t i v e \. [ 0 - 9 a - f ] { 20 } \. p n g / ) ) ;
87
89
}
0 commit comments