fix(compiler): Don't strip CSS source maps
Fix CSS source mapping for component by keeping `/*# sourceMappingURL= ... */` and `/*# sourceURL= ... */` comments. Relates to <https://github.com/angular/angular-cli/issues/4199>.
This commit is contained in:
parent
77747e10c0
commit
64b4be9670
|
@ -29,19 +29,20 @@ export function extractStyleUrls(
|
|||
resolver: UrlResolver, baseUrl: string, cssText: string): StyleWithImports {
|
||||
const foundUrls: string[] = [];
|
||||
|
||||
const modifiedCssText =
|
||||
cssText.replace(CSS_COMMENT_REGEXP, '').replace(CSS_IMPORT_REGEXP, (...m: string[]) => {
|
||||
const url = m[1] || m[2];
|
||||
if (!isStyleUrlResolvable(url)) {
|
||||
// Do not attempt to resolve non-package absolute URLs with URI scheme
|
||||
return m[0];
|
||||
}
|
||||
foundUrls.push(resolver.resolve(baseUrl, url));
|
||||
return '';
|
||||
});
|
||||
const modifiedCssText = cssText.replace(CSS_STRIPPABLE_COMMENT_REGEXP, '')
|
||||
.replace(CSS_IMPORT_REGEXP, (...m: string[]) => {
|
||||
const url = m[1] || m[2];
|
||||
if (!isStyleUrlResolvable(url)) {
|
||||
// Do not attempt to resolve non-package absolute URLs with URI
|
||||
// scheme
|
||||
return m[0];
|
||||
}
|
||||
foundUrls.push(resolver.resolve(baseUrl, url));
|
||||
return '';
|
||||
});
|
||||
return new StyleWithImports(modifiedCssText, foundUrls);
|
||||
}
|
||||
|
||||
const CSS_IMPORT_REGEXP = /@import\s+(?:url\()?\s*(?:(?:['"]([^'"]*))|([^;\)\s]*))[^;]*;?/g;
|
||||
const CSS_COMMENT_REGEXP = /\/\*[\s\S]+?\*\//g;
|
||||
const CSS_STRIPPABLE_COMMENT_REGEXP = /\/\*(?!#\s*(?:sourceURL|sourceMappingURL)=)[\s\S]+?\*\//g;
|
||||
const URL_WITH_SCHEMA_REGEXP = /^([^:/?#]+):/;
|
||||
|
|
|
@ -51,6 +51,14 @@ export function main() {
|
|||
expect(styleWithImports.styleUrls).not.toContain('http://ng.io/3.css');
|
||||
});
|
||||
|
||||
it('should keep /*# sourceURL... */ and /*# sourceMappingURL... */ comments', () => {
|
||||
const css =
|
||||
`/*regular comment*/\n/*# sourceURL=.... */\n/*# sourceMappingURL=... *//*#sourceMappingURL=... */`;
|
||||
const styleWithSourceMaps = extractStyleUrls(urlResolver, 'http://ng.io', css);
|
||||
expect(styleWithSourceMaps.style.trim())
|
||||
.toEqual('/*# sourceURL=.... */\n/*# sourceMappingURL=... *//*#sourceMappingURL=... */');
|
||||
});
|
||||
|
||||
it('should extract "@import url()" urls', () => {
|
||||
const css = `
|
||||
@import url('3.css');
|
||||
|
|
Loading…
Reference in New Issue