@@ -5,70 +5,70 @@ import {
55 StyleTagFactory ,
66 DEFAULT_REPLACE_CONFIG ,
77 FileCache ,
8- } from '../types'
9- import { isCSS , escapeRegExp } from '../utils'
8+ } from '../types' ;
9+ import { isCSS , escapeRegExp } from '../utils' ;
1010
1111export class BasePlugin {
12- protected cssStyleCache : FileCache = { }
12+ protected cssStyleCache : FileCache = { } ;
1313
1414 protected get replaceConfig ( ) {
15- return this . config . replace || DEFAULT_REPLACE_CONFIG
15+ return this . config . replace || DEFAULT_REPLACE_CONFIG ;
1616 }
1717
1818 protected get styleTagFactory ( ) : StyleTagFactory {
1919 return (
2020 this . config . styleTagFactory ||
2121 ( ( { style } ) => `<style type="text/css">${ style } </style>` )
22- )
22+ ) ;
2323 }
2424
2525 constructor ( protected readonly config : Config = { } ) { }
2626
2727 protected prepare ( { assets } : Compilation ) {
2828 Object . keys ( assets ) . forEach ( ( fileName ) => {
2929 if ( isCSS ( fileName ) && this . isCurrentFileNeedsToBeInlined ( fileName ) ) {
30- const source = assets [ fileName ] . source ( )
31- this . cssStyleCache [ fileName ] = typeof source === 'string' ? source : source . toString ( )
30+ const source = assets [ fileName ] . source ( ) ;
31+ this . cssStyleCache [ fileName ] = typeof source === 'string' ? source : source . toString ( ) ;
3232
3333 if ( ! this . config . leaveCSSFile ) {
34- delete assets [ fileName ]
34+ delete assets [ fileName ] ;
3535 }
3636 }
37- } )
37+ } ) ;
3838 }
3939
4040 protected getCSSStyle ( {
4141 cssLink,
4242 publicPath,
4343 } : {
44- cssLink : string
45- publicPath : string
44+ cssLink : string ;
45+ publicPath : string ;
4646 } ) : string | undefined {
4747 // Link pattern: publicPath + fileName + '?' + hash
4848 const fileName = cssLink
4949 . replace ( new RegExp ( `^${ escapeRegExp ( publicPath ) } ` ) , '' )
50- . replace ( / \? .+ $ / g, '' )
50+ . replace ( / \? .+ $ / g, '' ) ;
5151
5252 if ( this . isCurrentFileNeedsToBeInlined ( fileName ) ) {
53- const style = this . cssStyleCache [ fileName ]
53+ const style = this . cssStyleCache [ fileName ] ;
5454
5555 if ( style === undefined ) {
5656 console . error (
57- `Can not get css style for ${ cssLink } . It may be a bug of html-inline-css-webpack-plugin.` ,
58- )
57+ `无法获取 ${ cssLink } 的 CSS 样式。这可能是 html-inline-css-webpack-plugin 的一个 bug。`
58+ ) ;
5959 }
6060
61- return style
61+ return style ;
6262 } else {
63- return undefined
63+ return undefined ;
6464 }
6565 }
6666
6767 protected isCurrentFileNeedsToBeInlined ( fileName : string ) : boolean {
6868 if ( typeof this . config . filter === 'function' ) {
69- return this . config . filter ( fileName )
69+ return this . config . filter ( fileName ) ;
7070 } else {
71- return true
71+ return true ;
7272 }
7373 }
7474
@@ -77,31 +77,31 @@ export class BasePlugin {
7777 htmlFileName,
7878 style,
7979 } : {
80- html : string
81- htmlFileName : string
82- style : string
80+ html : string ;
81+ htmlFileName : string ;
82+ style : string ;
8383 } ) {
8484 const replaceValues = [
8585 this . styleTagFactory ( { style } ) ,
8686 this . replaceConfig . target ,
87- ]
87+ ] ;
8888
8989 if ( this . replaceConfig . position === 'after' ) {
90- replaceValues . reverse ( )
90+ replaceValues . reverse ( ) ;
9191 }
9292
9393 if ( html . indexOf ( this . replaceConfig . target ) === - 1 ) {
9494 throw new Error (
95- `Can not inject css style into "${ htmlFileName } ", as there is not replace target "${ this . replaceConfig . target } "` ,
96- )
95+ `无法将 CSS 样式注入到 "${ htmlFileName } ",因为找不到替换目标 "${ this . replaceConfig . target } "`
96+ ) ;
9797 }
9898
99- return html . replace ( this . replaceConfig . target , replaceValues . join ( '' ) )
99+ return html . replace ( this . replaceConfig . target , replaceValues . join ( '' ) ) ;
100100 }
101101
102102 protected cleanUp ( html : string ) {
103103 return this . replaceConfig . removeTarget
104104 ? html . replace ( this . replaceConfig . target , '' )
105- : html
105+ : html ;
106106 }
107107}
0 commit comments