Skip to content

Commit

Permalink
Add PWA support (#1086)
Browse files Browse the repository at this point in the history
## Motivation for the change, related issues

We want to [make Playground available
offline](#133).
This PR is a first step and adds support for installing Playground as a
PWA. Offline support will be implemented separately.

## Implementation details

The PR adds a `manifest.json` file and loads it on the Playground
website. This allows browsers to install Playground as a PWA

## Testing Instructions (or ideally a Blueprint)

- Checkout this branch
- Open Playground in [a browser that supports PWA
installing](https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Guides/Making_PWAs_installable#browser_support)
- Confirm that you can install Playground as a PWA
  • Loading branch information
bgrgicak authored Jun 12, 2024
1 parent 3e7ef3d commit ff955c1
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/playground/website/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
<link rel="stylesheet" href="/src/styles.css" />
<link rel="manifest" href="/manifest.json" />
<script
async
src="https://www.googletagmanager.com/gtag/js?id=G-SVTNFCP8T7"
Expand Down
32 changes: 32 additions & 0 deletions packages/playground/website/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"theme_color": "#ffffff",
"background_color": "#ffffff",
"display": "standalone",
"scope": "/",
"start_url": "/",
"short_name": "WordPress Playground",
"description": "WordPress Playground",
"name": "WordPress Playground",
"icons": [
{
"src": "/website-server/logo-192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/website-server/logo-256.png",
"sizes": "256x256",
"type": "image/png"
},
{
"src": "/website-server/logo-384.png",
"sizes": "384x384",
"type": "image/png"
},
{
"src": "/website-server/logo-512.png",
"sizes": "512x512",
"type": "image/png"
}
]
}
32 changes: 32 additions & 0 deletions packages/playground/website/manifest.production.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"theme_color": "#ffffff",
"background_color": "#ffffff",
"display": "standalone",
"scope": "/",
"start_url": "/",
"short_name": "WordPress Playground",
"description": "WordPress Playground",
"name": "WordPress Playground",
"icons": [
{
"src": "/logo-192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/logo-256.png",
"sizes": "256x256",
"type": "image/png"
},
{
"src": "/logo-384.png",
"sizes": "384x384",
"type": "image/png"
},
{
"src": "/logo-512.png",
"sizes": "512x512",
"type": "image/png"
}
]
}
Binary file added packages/playground/website/public/logo-192.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 packages/playground/website/public/logo-256.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 packages/playground/website/public/logo-384.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 packages/playground/website/public/logo-512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions packages/playground/website/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,23 @@ export default defineConfig(({ command, mode }) => {
}
},
} as Plugin,
/**
* Copy the `manifest.json` file to the `dist/` directory.
*/
{
name: 'manifest-plugin-build',
apply: 'build',
writeBundle({ dir: outputDir }) {
const manifestPath = path('./manifest.production.json');

if (existsSync(manifestPath) && outputDir) {
copyFileSync(
manifestPath,
join(outputDir, 'manifest.json')
);
}
},
} as Plugin,
],

// Configuration for building your library.
Expand Down

0 comments on commit ff955c1

Please sign in to comment.