vue中添加favicon.ico


在vue路由模式中添加favicon.ico語普通頁面不同,僅僅在header中添加是沒有效果的。

1、首先將favicon.ico圖片放在根目錄下

2、修改webpack配置文件
(1)找到build下的webpack.dev.conf.js文件

在plugins:[]下加入:

    new HtmlWebpackPlugin({
      filename: 'index.html',
      template: 'index.html',
      inject: true,
      favicon: path.resolve('favicon.ico')
    }),


(2)找到build下的webpack.prod.conf.js文件

同樣的在在plugins:[]下加入:

new HtmlWebpackPlugin({
      filename: process.env.NODE_ENV === 'testing'
        ? 'index.html'
        : config.build.index,
      template: 'index.html',
      inject: true,
      favicon: path.resolve('favicon.ico'),
      minify: {
        removeComments: true,
        collapseWhitespace: true,
        removeAttributeQuotes: true
        // more options:
        // https://github.com/kangax/html-minifier#options-quick-reference
      },
      // necessary to consistently work with multiple chunks via CommonsChunkPlugin
      chunksSortMode: 'dependency'
    }),


修改配置文件后需重啟npm run dev ,

打包后,可以看到根目錄下多了一個網頁icon。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM