Skip to content

Commit 5b8f9b0

Browse files
authored
Merge pull request #1 from rojoca/replace-link-with-style
Replace link tags with style
2 parents c2d192d + c911cf2 commit 5b8f9b0

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/index.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,12 @@ interface Config {
1818
}
1919

2020
export default class Plugin
21-
{
22-
static addStyle(html: string, style: string) {
23-
return html.replace('</head>', `<style>${style}</style></head>`);
24-
}
25-
26-
static removeLinkTag(html: string, cssFileName: string) {
21+
{
22+
static replaceLinkWithStyle(html: string, style: string, cssFileName: string) {
2723
return html.replace(
2824
new RegExp(`<link[^>]+href=['"]${cssFileName}['"][^>]+(>|\/>|><\/link>)`),
29-
'',
30-
);
25+
`<style>${style}</style>`
26+
);
3127
}
3228

3329
private config: Config;
@@ -71,8 +67,7 @@ export default class Plugin
7167
let html = this.html[htmlFileName];
7268

7369
Object.keys(this.css).forEach((key) => {
74-
html = Plugin.addStyle(html, this.css[key]);
75-
html = Plugin.removeLinkTag(html, publicPath + key);
70+
html = Plugin.replaceLinkWithStyle(html, this.css[key], publicPath + key);
7671
});
7772

7873
assets[htmlFileName] = {
@@ -94,4 +89,4 @@ export default class Plugin
9489
function is(filenameExtension: string) {
9590
const reg = new RegExp(`\.${filenameExtension}$`);
9691
return (fileName: string) => reg.test(fileName);
97-
}
92+
}

0 commit comments

Comments
 (0)