Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change favicon? #6155

Closed
cesalberca opened this issue Mar 18, 2019 · 9 comments
Closed

How to change favicon? #6155

cesalberca opened this issue Mar 18, 2019 · 9 comments

Comments

@cesalberca
Copy link

Describe the bug

We are unable to set a custom favicon for the storybook static build and development. We've tried using HtmlWebpackPlugin, setting the icon with different urls in the preview-header.html and manager-header.html having imported the 'favicon.ico' in the config.js as follows:

import {
  configure,
  addParameters,
  addDecorator
} from '@storybook/vue'
import {
  Vue
} from 'vue-property-decorator'
import {
  Centered
} from './components/centered'
import {
  Installer
} from '../src/Installer'
import {
  withKnobs
} from '@storybook/addon-knobs'
import '../src/assets/variables.css'
import '../src/assets/theme.css'
import '../src/assets/base.css'
import '../src/sass/main.scss'
import {
  withInfo
} from 'storybook-addon-vue-info'
// We import the favicon here
import './favicon.ico'

Vue.component('Centered', Centered)

const installer = new Installer(Vue)
installer.install(true)

addParameters({
  options: {
    sortStoriesByKind: true
  }
})

const stories = require.context('../src', true, /.stories.ts$/)

function loadStories() {
  stories.keys().forEach(filename => stories(filename))
}

addDecorator(withKnobs)
addDecorator(withInfo)

configure(loadStories, module)

And the preview-header.html (or manager-header.html):

<link rel="shortcut icon" href="./favicon.ico">

We've tried these routes too:

<link rel="icon" href="<%= BASE_URL %>favicon.ico">

And

<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">

Using the first option we see that the favicon is broken, however we don't see in the bundle the favicon.

System:

  • OS: MacOS
  • Device: Macbook Pro 2019
  • Browser: All
  • Framework: Vue
  • Version: 5.0.3
@shilman
Copy link
Member

shilman commented Mar 19, 2019

Here's my setup. First in package.json scripts:

"storybook": "start-storybook -p 9009 -s public"

Then in .storybook/manager-head.html (NOT manager-header.html):

<link rel="shortcut icon" href="/storybook.ico">
<link rel="icon" type="image/png" href="/storybook.png" sizes="192x192">

Then in public:

$ ls public/
storybook.ico	storybook.png

Hope that helps!

@cesalberca
Copy link
Author

cesalberca commented Mar 19, 2019

My bad, I meant .storybook/manager-head.html. Works perfectly now, thanks! Maybe adding this to the docs would help other people too 🙂

@seantomlins
Copy link

Solution I figured out to replace the default

  1. Create a static asset directory i.e. .storybook/public
  2. Add it to .storybook/main.js as a staticDir
module.exports = {
  staticDirs: ['./public'],
};
  1. Add your favicon.ico file to public

I believe it works because it's copying the static directory files to the site root which overwrites the favicon.ico, but it could be some other dark magic

I tried the manager-head.html solution but it was outputting the html into the body instead of the head. Not sure it that's a bug in v6.4.19 or if that's expected

@sag1v
Copy link

sag1v commented May 30, 2022

@shilman approach didn't help in my case nor @seantomlins's approach (for some reason)
Unfortunately there is no clear way of overriding the favicon, shame its not documented.

I ended up doing this hack in manager.js

// manager.js

import favicon from './assets/favicon.ico';

const link = document.createElement('link');
link.setAttribute('rel', 'shortcut icon');
link.setAttribute('href', favicon);
document.head.appendChild(link);

nate-ni added a commit to ni/nimble that referenced this issue Sep 6, 2022
# Pull Request

## 🤨 Rationale
The favicon in the Storybook site was non existent. Updating it to the Nimble icon.

Used this information to help direct me to updating it:
[How to change favicon? (Storybook GitHub)](storybookjs/storybook#6155)
[Reference example from the MS Fluent Storybook Repo](https://github.com/microsoft/fluentui/blob/4c970883a796505b132b356aa03302c068eb0ea9/packages/web-components/.storybook/manager-head.html)

I think this replaces this closed pull request: #217 

## 👩‍💻 Implementation
- Added ICO and PNG versions of the Nimble Icon
- Created an HTML file to reference them as the favicon
- Updated the npm command 'storybook' to add the image files directory

## 🧪 Testing
Ran storybook locally to make sure it displays the favicon correctly.

<img width="871" alt="image" src="https://user-images.githubusercontent.com/109235103/187926080-0cedfec7-ea43-4453-a316-69f36ba0ddbf.png">

<img width="481" alt="image" src="https://user-images.githubusercontent.com/109235103/187926268-c222d54b-1eb6-420c-8d09-b249e8b5f368.png">



## ✅ Checklist
- [x ] I have updated the project documentation to reflect my changes or determined no changes are needed.
@alvara
Copy link

alvara commented Nov 22, 2022

Thanks @sag1v , this was the only solution that worked for me.

@LeandrodeLimaC
Copy link

I'm using Storybook v7 and @seantomlins solution works fine!

@soumitya0
Copy link

Just rename the file that you want to show as favicon to favicon.svg and upload inside public folder

@technbuzz
Copy link

I second with @soumitya0 solution, this works for version 7.6.16

@bastiendmt
Copy link

I struggled to achieve this. I manage to do it by :

  • creating a .storybook/public/favicon.svg this folder contains other file aswell
  • exposing this folder in main.ts, with staticDirs with './public'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants