diff --git a/package.json b/package.json index 2d7b0d9..7705200 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "html-inline-css-webpack-plugin", + "name": "@rojoca/html-inline-css-webpack-plugin", "version": "1.2.1", "description": "A webpack plugin for convert external style sheet to internal style sheet", "main": "./build/index.js", @@ -9,7 +9,7 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/Runjuu/html-inline-css-webpack-plugin.git" + "url": "git+https://github.com/rojoca/html-inline-css-webpack-plugin.git" }, "keywords": [ "webpack", @@ -25,9 +25,9 @@ "author": "Runjuu", "license": "MIT", "bugs": { - "url": "https://github.com/Runjuu/html-inline-css-webpack-plugin/issues" + "url": "https://github.com/rojoca/html-inline-css-webpack-plugin/issues" }, - "homepage": "https://github.com/Runjuu/html-inline-css-webpack-plugin#readme", + "homepage": "https://github.com/rojoca/html-inline-css-webpack-plugin#readme", "devDependencies": { "@types/webpack": "^4.4.0", "tslib": "^1.9.2", 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 +}