Home > Web Front-end > Vue.js > How to add favicon icon in vue.js

How to add favicon icon in vue.js

coldplay.xixi
Release: 2020-11-30 13:57:13
Original
2496 people have browsed it

How to add favicon icon to vue.js: 1. Modify the [index.html] file, the code is [

The operating environment of this tutorial: windows10 system, vue2.9, this article applies to all brands of computers.

【Recommended related articles: vue.js

How to add favicon icon in vue.js:

Method One: Modify the index.html file

<link rel="shortcut icon" type="image/x-icon" href="favicon.ico"/>
Copy after login

Disadvantage: You need to copy favicon.ico to the root directory after packaging

Method Two: Modify the webpack configuration file

1. Find the webpack.dev.conf.js file under build

new HtmlWebpackPlugin({
filename: &#39;index.html&#39;,
template: &#39;index.html&#39;,
inject: true,
favicon: path.resolve(&#39;favicon.ico&#39;) // 新增
}),
Copy after login

2. Find the webpack.prod.conf.js file under build

new HtmlWebpackPlugin({
filename: config.build.index,
template: &#39;index.html&#39;,
inject: true,
favicon: path.resolve(&#39;favicon.ico&#39;), //新增
minify: {
emoveComments: true,
collapseWhitespace: true,
removeAttributeQuotes: true
...
}),
Copy after login

Method 3: The favicon cannot be displayed normally after the vue project is packaged

Solution:

HtmlWebpackPlugin plug-in option in webpack.prod.config.js Configure the favicon option in, where the path of the favicon is a relative path

new HtmlWebpackPlugin({
filename: &#39;index.html&#39;,
template: &#39;index.html&#39;,
favicon: &#39;src/assets/img/favicon.ico&#39;,
inject: true
}),
Copy after login

You need to restart after modifying the configuration filenpm run dev

There will be a favicon in the root directory after packaging. ico

Related free learning recommendations: JavaScript (video)

The above is the detailed content of How to add favicon icon in vue.js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template