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 new faviconPath option #312

Closed
wants to merge 5 commits into from
Closed
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-gorillas-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'playroom': patch
---

Added new `faviconPath` option
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ module.exports = {
widths: [320, 768, 1024],
port: 9000,
openBrowser: true,
faviconPath: './favicon.svg',
paramType: 'search', // default is 'hash'
exampleCode: `
<Button>
Expand Down
1 change: 1 addition & 0 deletions cypress/projects/basic/playroom.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ module.exports = {
outputPath: './dist',
openBrowser: false,
storageKey: 'playroom-example-basic',
faviconPath: '../../../images/favicon.svg',
};
1 change: 1 addition & 0 deletions cypress/projects/themed/playroom.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ module.exports = {
paramType: 'search',
port: 9001,
storageKey: 'playroom-example-themed',
faviconPath: '../../../images/favicon.svg',
};
1 change: 1 addition & 0 deletions cypress/projects/typescript/playroom.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
outputPath: './dist',
openBrowser: false,
storageKey: 'playroom-example-typescript',
faviconPath: '../../../images/favicon.svg',
webpackConfig: () => ({
module: {
rules: [
Expand Down
Binary file removed images/favicon-inverted.png
Binary file not shown.
Binary file removed images/favicon.png
Binary file not shown.
9 changes: 9 additions & 0 deletions images/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion lib/makeWebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ module.exports = async (playroomConfig, options) => {

const staticTypes = await getStaticTypes(playroomConfig);

// Use the favicon from the config if specified, otherwise don't use anything
const favicon = playroomConfig.faviconPath
? relativeResolve(playroomConfig.faviconPath)
: undefined;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've defaulted to undefined here because I believe the /images folder is not published to npm, and I'm not sure if you want to do that. However, I'm happy to change this if needed.


const ourConfig = {
mode: options.production ? 'production' : 'development',
entry: {
Expand Down Expand Up @@ -167,7 +172,7 @@ module.exports = async (playroomConfig, options) => {
chunksSortMode: 'none',
chunks: ['index'],
filename: 'index.html',
favicon: 'images/favicon.png',
favicon,
base: playroomConfig.baseUrl,
}),
new HtmlWebpackPlugin({
Expand All @@ -181,6 +186,7 @@ module.exports = async (playroomConfig, options) => {
chunksSortMode: 'none',
chunks: ['preview'],
filename: 'preview/index.html',
favicon,
publicPath: '../',
}),
new VanillaExtractPlugin(),
Expand Down
11 changes: 0 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ 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 @@ -16,15 +14,6 @@ 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