Skip to content

Commit 80a973c

Browse files
authored
Merge pull request #33 from LukeLin/v4
fix: 修复link标签和script标签中间有换行符匹配不到的问题
2 parents 384a2e8 + 555df98 commit 80a973c

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module.exports = {
1515
"no-mixed-spaces-and-tabs": 0,
1616
"semi": 2,
1717
"no-useless-escape": 0,
18+
"no-control-regex": 0
1819
},
1920
"globals": {
2021
"describe": true,

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,5 @@
7979
- v4.0.1 支持 webpack4.x
8080
- v4.0.2 修复 watch 模式下资源重复的问题
8181
- v4.0.3 修复外链 favico 的问题
82-
- v4.0.4 修复 favico 文件不存在报错
82+
- v4.0.4 修复 favico 文件不存在报错
83+
- v4.0.5 修复link标签和script标签中间有换行符匹配不到的问题

index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,9 @@ HtmlResWebpackPlugin.prototype.checkResource = function(
400400
compilation
401401
) {
402402
let isProduction = this.options.env === "production",
403-
linkRegex = new RegExp("(<link[^>]*href=(['\"]*)(.*?)(['\"]*).*?>)", "ig"),
403+
linkRegex = new RegExp("(<link(?:[^>]|\n)*href=(['\"]*)(.*?)(['\"]*).*?>)", "ig"),
404404
scriptRegex = new RegExp(
405-
"(<script[^>]*src=(['\"]*)(.*?)(['\"]*).*?>(</script>)?)",
405+
"(<script(?:[^>]|\n)*src=(['\"]*)(.*?)(['\"]*).*?>(</script>)?)",
406406
"ig"
407407
);
408408

@@ -425,7 +425,7 @@ HtmlResWebpackPlugin.prototype.checkResource = function(
425425
if (!!~route.indexOf("__inline")) {
426426
// css inline
427427
let styleInlineRegex = new RegExp(
428-
"<link.*href=(s*?)*(.+)[?]__inline.*?(s*?)>",
428+
"<link(?:[^>]|\n)*href=(s*?)*(.+)[?]__inline.*?(s*?)>",
429429
"ig"
430430
);
431431
route = this.inlineHtmlRes(
@@ -436,7 +436,7 @@ HtmlResWebpackPlugin.prototype.checkResource = function(
436436
);
437437
} else {
438438
// css md5
439-
let styleMd5Regex = new RegExp("<link.*href=(s*?)*(.+).*?(s*?)>", "ig");
439+
let styleMd5Regex = new RegExp("<link(?:[^>]|\n)*href=(s*?)*(.+).*?(s*?)>", "ig");
440440
let cssPublicPath = this.options.cssPublicPath || publicPath;
441441
route = this.md5HtmlRes(route, styleMd5Regex, cssPublicPath);
442442
}
@@ -462,7 +462,7 @@ HtmlResWebpackPlugin.prototype.checkResource = function(
462462
if (!!~route.indexOf("__inline")) {
463463
// js inline
464464
let scriptInlineRegex = new RegExp(
465-
"<script.*src=(s*?)*(.+)[?]__inline.*?(s*?)></script>",
465+
"<script(?:[^>]|\n)*src=(s*?)*(.+)[?]__inline.*?(s*?)></script>",
466466
"ig"
467467
);
468468
route = this.inlineHtmlRes(
@@ -474,7 +474,7 @@ HtmlResWebpackPlugin.prototype.checkResource = function(
474474
} else {
475475
// js md5
476476
let scriptMd5Regex = new RegExp(
477-
"<script.*src=(s*?)*(.+).*?(s*?)></script>",
477+
"<script(?:[^>]|\n)*src=(s*?)*(.+).*?(s*?)></script>",
478478
"ig"
479479
);
480480
route = this.md5HtmlRes(route, scriptMd5Regex, publicPath);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "html-res-webpack-plugin",
3-
"version": "4.0.4",
3+
"version": "4.0.5",
44
"description": "html generation and resource inline or md5 for webpack",
55
"keywords": [
66
"front-end",

0 commit comments

Comments
 (0)