diff --git a/src/index.ts b/src/index.ts index 49d532b..8a21b67 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,16 +18,12 @@ interface Config { } export default class Plugin -{ - static addStyle(html: string, style: string) { - return html.replace('', ``); - } - - static removeLinkTag(html: string, cssFileName: string) { +{ + static replaceLinkWithStyle(html: string, style: string, cssFileName: string) { return html.replace( new RegExp(`]+href=['"]${cssFileName}['"][^>]+(>|\/>|><\/link>)`), - '', - ); + `` + ); } private config: Config; @@ -71,8 +67,7 @@ export default class Plugin let html = this.html[htmlFileName]; Object.keys(this.css).forEach((key) => { - html = Plugin.addStyle(html, this.css[key]); - html = Plugin.removeLinkTag(html, publicPath + key); + html = Plugin.replaceLinkWithStyle(html, this.css[key], publicPath + key); }); assets[htmlFileName] = { @@ -94,4 +89,4 @@ export default class Plugin function is(filenameExtension: string) { const reg = new RegExp(`\.${filenameExtension}$`); return (fileName: string) => reg.test(fileName); -} \ No newline at end of file +}