1- import * as fs from 'fs' ;
21import { ng } from '../../utils/process' ;
32import {
43 expectFileToMatch ,
54 expectFileToExist ,
65 expectFileMatchToExist ,
76 writeMultipleFiles
87} from '../../utils/fs' ;
8+ import { copyProjectAsset } from '../../utils/assets' ;
99import { expectToFail } from '../../utils/utils' ;
1010import { getGlobalVariable } from '../../utils/env' ;
1111
@@ -26,32 +26,34 @@ export default function () {
2626 . then ( ( ) => writeMultipleFiles ( {
2727 'src/styles.css' : `
2828 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 '); }
3030 ` ,
3131 'src/app/app.component.css' : `
3232 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 '); }
3434 ` ,
35- // Using SVGs because they are loaded via file-loader and thus never inlined.
3635 '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
4037 } ) )
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' ) )
4141 . then ( ( ) => ng ( 'build' , '--extract-css' , '--aot' ) )
4242 // Check paths are correctly generated.
4343 . then ( ( ) => expectFileToMatch ( 'dist/styles.bundle.css' , '/assets/global-img-absolute.svg' ) )
4444 . 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 / ) )
4648 . then ( ( ) => expectFileToMatch ( 'dist/main.bundle.js' ,
4749 '/assets/component-img-absolute.svg' ) )
4850 . 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 / ) )
5052 // Check files are correctly created.
5153 . then ( ( ) => expectToFail ( ( ) => expectFileToExist ( 'dist/global-img-absolute.svg' ) ) )
5254 . 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 / ) )
5557 // Check urls with deploy-url scheme are used as is.
5658 . then ( ( ) => ng ( 'build' , '--base-href=/base/' , '--deploy-url=http://deploy.url/' ,
5759 '--extract-css' ) )
@@ -79,9 +81,9 @@ export default function () {
7981 . then ( ( ) => expectFileToMatch ( 'dist/styles.bundle.css' ,
8082 '/base/deploy/assets/global-img-absolute.svg' ) )
8183 . 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 / ) )
8385 . then ( ( ) => expectFileToMatch ( 'dist/main.bundle.js' ,
8486 '/base/deploy/assets/component-img-absolute.svg' ) )
8587 . 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 / ) ) ;
8789}
0 commit comments