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

Add favicon to Playroom site #309

Merged
merged 9 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/mean-moons-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'playroom': patch
---

Add favicon to Playroom site.
Binary file added images/favicon-inverted.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions lib/makeWebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ module.exports = async (playroomConfig, options) => {
include: path.dirname(require.resolve('codemirror/package.json')),
use: [MiniCssExtractPlugin.loader, require.resolve('css-loader')],
},
{
test: /\.png$/i,
type: 'asset/resource',
},
],
},
optimization: {
Expand All @@ -163,6 +167,7 @@ module.exports = async (playroomConfig, options) => {
chunksSortMode: 'none',
chunks: ['index'],
filename: 'index.html',
favicon: 'images/favicon.png',
Copy link

@david10sing david10sing Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this have come from playroomConfig? Could this be coming from a public folder too. But offering it in the playroomConfig would make it more flexible.

Currently getting an error when building playroom.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey David, could you log the error as an Issue with a reproduction? Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting an error too:

Error: HtmlWebpackPlugin: could not load file /<path-to-project>/images/favicon.png

base: playroomConfig.baseUrl,
}),
new HtmlWebpackPlugin({
Expand Down
11 changes: 11 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { renderElement } from './render';
import Playroom from './Playroom/Playroom';
import { StoreProvider } from './StoreContext/StoreContext';
import playroomConfig from './config';
import faviconPath from '../images/favicon.png';
import faviconInvertedPath from '../images/favicon-inverted.png';

const polyfillIntersectionObserver = () =>
typeof window.IntersectionObserver !== 'undefined'
Expand All @@ -14,6 +16,15 @@ polyfillIntersectionObserver().then(() => {
const outlet = document.createElement('div');
document.body.appendChild(outlet);

const selectedElement = document.head.querySelector('link[rel="icon"]');
const favicon = window.matchMedia('(prefers-color-scheme: dark)').matches
? faviconInvertedPath
: faviconPath;

if (selectedElement) {
selectedElement.setAttribute('href', favicon);
}

const renderPlayroom = ({
themes = require('./themes'),
components = require('./components'),
Expand Down