tools/gulp/inline-resources.js
function inlineStyle(content, urlResolver) {
  return content.replace(/styleUrls\s*:\s*(\[[\s\S]*?\])/gm, function (m, styleUrls) {
    const urls = eval(styleUrls);
    return 'styles: ['
      + urls.map(styleUrl => {
        const styleFile = urlResolver(styleUrl);
        const originContent = fs.readFileSync(styleFile, 'utf-8');
        const styleContent = styleFile.endsWith('.scss') ? buildSass(originContent, styleFile) : originContent;
        const shortenedStyle = styleContent
          .replace(/([\n\r]\s*)+/gm, ' ')
          .replace(/"/g, '\\"');
        return `"${shortenedStyle}"`;
      })
        .join(',\n')
      + ']';
  });
}
function inlineStyle(content, urlResolver) {
  return content.replace(/styleUrls\s*:\s*(\[[\s\S]*?\])/gm, function (m, styleUrls) {
    const urls = eval(styleUrls);
    return 'styles: ['
      + urls.map(styleUrl => {
        const styleFile = urlResolver(styleUrl);
        const originContent = fs.readFileSync(styleFile, 'utf-8');
        const styleContent = styleFile.endsWith('.scss') ? buildSass(originContent, styleFile) : originContent;
        const shortenedStyle = styleContent
          .replace(/([\n\r]\s*)+/gm, ' ')
          .replace(/"/g, '\\"');
        return `"${shortenedStyle}"`;
      })
        .join(',\n')
      + ']';
  });
}
function inlineStyle ( content , urlResolver ) { return content . replace ( / styleUrls\s*:\s*(\[[\s\S]*?\]) / gm , function ( m , styleUrls ) { const urls = eval ( styleUrls ) ; return 'styles: [' + urls . map ( styleUrl => { const styleFile = urlResolver ( styleUrl ) ; const originContent = fs . readFileSync ( styleFile , 'utf-8' ) ; const styleContent = styleFile . endsWith ( '.scss' ) ? buildSass ( originContent , styleFile ) : originContent ; const shortenedStyle = styleContent . replace ( / ([\n\r]\s*)+ / gm , ' ' ) . replace ( / " / g , '\\"' ) ; return ` ${ shortenedStyle } ` ; } ) . join ( ',\n' ) + ']' ; } ) ; }
Inline the styles for a source file. Simply search for instances of `styleUrls: [...]` and
replace with `styles: [...]` (with the content of the file included).
@param urlResolver {Function} A resolver that takes a URL and return a path.
@param content {string} The source file's content.
@return {string} The content with all styles inlined.
Inline the styles for a source file . Simply search for instances of styleUrls : [ ... ] and replace with styles : [ ... ] ( with the content of the file included ) .