Skip to content

Commit 384a2e8

Browse files
committed
fix favico not exist error
1 parent 8039c70 commit 384a2e8

12 files changed

Lines changed: 174 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
- v4.0.1 Support webpack4.x
3939
- v4.0.2 Fix duplicate resource in watch mode
4040
- v4.0.3 fix external favico issue
41+
- v4.0.4 fix favico not exist error
4142

4243
## 中文
4344
- v0.0.1 html生成及相关js,css资源内联
@@ -77,4 +78,5 @@
7778
- v3.2.6 若注入资源中,如果没有引入资源,会让程序继续运行
7879
- v4.0.1 支持 webpack4.x
7980
- v4.0.2 修复 watch 模式下资源重复的问题
80-
- v4.0.3 修复外链 favico 的问题
81+
- v4.0.3 修复外链 favico 的问题
82+
- v4.0.4 修复 favico 文件不存在报错

index.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,18 @@ HtmlResWebpackPlugin.prototype.apply = function(compiler) {
188188
);
189189

190190
// inject favicon
191-
if (this.options.favicon) {
192-
this.options.faviconFileName = this.addFileToWebpackAsset(
193-
compilation,
194-
this.options.favicon,
195-
utils.getBaseName(this.options.favicon, null)
196-
);
191+
let favicon = this.options.favicon;
192+
if (favicon) {
193+
if (!fs.existsSync(favicon)) {
194+
utils.alert(`Favicon file does not exist: ${this.options.favicon}`, 1);
195+
}
196+
else {
197+
this.options.faviconFileName = this.addFileToWebpackAsset(
198+
compilation,
199+
favicon,
200+
utils.getBaseName(favicon, null)
201+
);
202+
}
197203
}
198204

199205
// webpack options

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.3",
3+
"version": "4.0.4",
44
"description": "html generation and resource inline or md5 for webpack",
55
"keywords": [
66
"front-end",

runWebpack/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var webpackConfig = [
3030
require(basePath + "/resource-favico/webpack.config.js"), // generate favicon
3131
require(basePath + "/resource-favico-1/webpack.config.js"), // html mode generate favicon
3232
require(basePath + "/resource-favico-2/webpack.config.js"), // html mode external favicon
33+
require(basePath + "/resource-favico-3/webpack.config.js"), // no favicon file but fill in the option
3334
require(basePath + "/resource-common-1/webpack.config.js"), // common chunk generated by webpack
3435
require(basePath + "/resource-common-2/webpack.config.js"), // html mode common chunk generated by webpack
3536
require(basePath + "/resource-copy-plugin-1/webpack.config.js"), // usage with copy-webpack-plugin-hash
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!doctype html>
2+
<html lang="zh">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Tencent QQ</title>
6+
<link rel="shortcut icon" type="image/x-icon" href="//im.qq.com/favicon.ico">
7+
<link rel="icon" type="image/x-icon" href="//im.qq.com/favicon.ico">
8+
<script src="//localhost:9000/[libs/react.js]"></script>
9+
<link rel="stylesheet" href="//localhost:9000/[js/index.css]">
10+
</head>
11+
<body>
12+
<div id="pages" class="qq-ui"></div>
13+
14+
15+
16+
<script src="//localhost:9000/[js/index.js]"></script>
17+
</body>
18+
</html>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!doctype html>
2+
<html lang="zh">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Tencent QQ</title>
6+
<link rel="shortcut icon" type="image/x-icon" href="//im.qq.com/favicon.ico">
7+
<link rel="icon" type="image/x-icon" href="//im.qq.com/favicon.ico">
8+
<script src="libs/react.js"></script>
9+
<link rel="stylesheet" href="js/index.css">
10+
</head>
11+
<body>
12+
<div id="pages" class="qq-ui"></div>
13+
14+
15+
16+
<script src="js/index.js"></script>
17+
</body>
18+
</html>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
require('./index.less');
3+
4+
var a = "hello world!";
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
html, body {
2+
margin: 0;
3+
padding: 0;
4+
}
5+
6+
.img {
7+
background-url: url("./logo.png");
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var react = {
2+
reactDom: function() {
3+
4+
}
5+
};
4.09 KB
Loading

0 commit comments

Comments
 (0)