import { minify } from 'html-minifier' ; import { SourceMapGenerator , RawSourceMap } from 'source-map' ; import { LoaderContext } from './LoaderContext' ; const minifierOptions = { caseSensitive : false , collapseBooleanAttributes : true , collapseInlineTagWhitespace : false , collapseWhitespace : true , conservativeCollapse : true , continueOnParseError : false , decodeEntities : false , html5 : true , includeAutoGeneratedTags : true , keepClosingSlash : true , minifyCSS : false , minifyJS : false , minifyURLs : false , preserveLineBreaks : false , preventAttributesEscaping : false , processConditionalComments : false , removeAttributeQuotes : false , removeComments : true , removeEmptyAttributes : false , removeEmptyElements : false , removeOptionalTags : false , removeRedundantAttributes : true , removeScriptTypeAttributes : false , removeStyleLinkTypeAttributes : false , removeTagWhitespace : false , sortAttributes : false , sortClassName : false , trimCustomFragments : false , useShortDoctype : false } ; export = function ( this , html ) : void { let template = minify ( html , minifierOptions ) . trim ( ) ; template = 'module.exports = ' + JSON . stringify ( template ) ; if ( this . sourceMap ) { const gen = new SourceMapGenerator ( { file : this . resourcePath + '.js' } ) ; gen . addMapping ( { source : this . resourcePath , generated : { column : 0 , line : 1 } , original : { column : 0 , line : 1 } } ) ; gen . setSourceContent ( this . resourcePath , html ) ; const sm = JSON . parse ( gen . toString ( ) ) ; this . callback ( null , template , sm ) ; } else { this . callback ( null , template ) ; } } ;