Added proper IWA support
This commit is contained in:
@@ -13,8 +13,8 @@ Open `dist/index.html` directly in any browser—no server required.
|
|||||||
|
|
||||||
## Build Targets
|
## Build Targets
|
||||||
|
|
||||||
- **Singlefile HTML** (`SINGLEFILE=1 vite build`) — self-contained, offline-capable
|
- **Singlefile HTML** (`SINGLEFILE=1 vite build`) — self-contained, offline-capable (~16KB)
|
||||||
- **IWA/Chrome Extension** — load popup from `public/manifest.json`
|
- **IWA/Chrome Extension** (`npm run build:iwa`) — Installer for Web Applications manifest at `public/iwa/manifest.json`
|
||||||
- **PWA** — installable app with service worker in `dist/sw.js`
|
- **PWA** — installable app with service worker in `dist/sw.js`
|
||||||
|
|
||||||
## Project Structure
|
## Project Structure
|
||||||
@@ -24,8 +24,8 @@ src/ # React components (App.jsx, Editor.jsx, Toolbar.jsx)
|
|||||||
components/ # MarkdownEditor, LaTeXRenderer, SvgRenderer
|
components/ # MarkdownEditor, LaTeXRenderer, SvgRenderer
|
||||||
hooks/ # useTheme, useKeyboardShortcuts
|
hooks/ # useTheme, useKeyboardShortcuts
|
||||||
utils/ # exportDocx, importDocx, fileIo, exportPdf
|
utils/ # exportDocx, importDocx, fileIo, exportPdf
|
||||||
public/ # sample.md, favicon.svg, icons.svg
|
public/ # sample.md, favicon.svg, icons.svg, iwa/ (Chrome extension manifest)
|
||||||
dist/ # Production build (single index.html + manifest.json)
|
dist/ # Production build (single index.html + assets)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Toolchain Quirks
|
## Toolchain Quirks
|
||||||
|
|||||||
61
iwa-build.js
Executable file
61
iwa-build.js
Executable file
@@ -0,0 +1,61 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
/**
|
||||||
|
* IWA (Installer for Web Applications) Build Script
|
||||||
|
* Generates Chrome extension manifest and required files for deployment.
|
||||||
|
*
|
||||||
|
* Usage: npm run build:iwa
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'fs';
|
||||||
|
import { join, dirname } from 'path';
|
||||||
|
import { fileURLToPath } from 'url';
|
||||||
|
|
||||||
|
const __dirname = join(
|
||||||
|
dirname(fileURLToPath(import.meta.url)),
|
||||||
|
'.'
|
||||||
|
);
|
||||||
|
|
||||||
|
// Read existing manifest for reference
|
||||||
|
const distManifestPath = join(__dirname, 'dist', 'manifest.json');
|
||||||
|
try {
|
||||||
|
const distManifest = JSON.parse(readFileSync(distManifestPath, 'utf-8'));
|
||||||
|
|
||||||
|
// Generate IWA manifest with Chrome-specific fields
|
||||||
|
const iwaManifest = {
|
||||||
|
name: distManifest.name,
|
||||||
|
short_name: distManifest.short_name,
|
||||||
|
description: distManifest.description,
|
||||||
|
version: distManifest.version || '1.0.0',
|
||||||
|
start_url: '../index.html',
|
||||||
|
display: distManifest.display || 'standalone',
|
||||||
|
default_locale: 'en-US',
|
||||||
|
installable: true,
|
||||||
|
background_color: distManifest.background_color,
|
||||||
|
theme_color: distManifest.theme_color,
|
||||||
|
icons: distManifest.icons.map(icon => ({
|
||||||
|
src: icon.src,
|
||||||
|
sizes: icon.sizes,
|
||||||
|
type: icon.type,
|
||||||
|
purpose: 'any maskable'
|
||||||
|
}))
|
||||||
|
};
|
||||||
|
|
||||||
|
// Write IWA manifest
|
||||||
|
const iwaDir = join(__dirname, 'public', 'iwa');
|
||||||
|
if (!existsSync(iwaDir)) {
|
||||||
|
mkdirSync(iwaDir, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
writeFileSync(join(iwaDir, 'manifest.json'), JSON.stringify(iwaManifest, null, 2));
|
||||||
|
|
||||||
|
console.log('✅ IWA manifest generated at:', join(iwaDir, 'manifest.json'));
|
||||||
|
console.log('');
|
||||||
|
console.log('📦 Deployment instructions:');
|
||||||
|
console.log(' 1. Copy /public/iwa to your package directory (e.g., /usr/local/share/applications/iwa/)');
|
||||||
|
console.log(' 2. The manifest references index.html which loads from the main dist/index.html');
|
||||||
|
console.log(' 3. Chrome will detect this and offer installation via the Chrome Store');
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Build failed:', error.message);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"build:single": "SINGLEFILE=1 vite build",
|
"build:single": "SINGLEFILE=1 vite build",
|
||||||
|
"build:iwa": "npm run build && node iwa-build.js",
|
||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
30
public/iwa.html
Normal file
30
public/iwa.html
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: blob: https://fonts.googleapis.com; font-src data: https://fonts.gstatic.com/; style-src 'self' 'unsafe-inline' data: https://fonts.googleapis.com; script-src 'self' 'strict-dynamic'; img-src 'self' data: blob: https://fonts.gstatic.com;">
|
||||||
|
|
||||||
|
<title>AboveTheMark - GFM Editor</title>
|
||||||
|
|
||||||
|
<!-- IWA manifest -->
|
||||||
|
<link rel="manifest" href="/iwa/manifest.json">
|
||||||
|
|
||||||
|
<!-- Favicon -->
|
||||||
|
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
|
||||||
|
<link rel="apple-touch-icon" href="/favicon.svg">
|
||||||
|
|
||||||
|
<!-- PWA meta tags for IWA compatibility -->
|
||||||
|
<meta name="theme-color" content="#0969da">
|
||||||
|
<meta name="msapplication-TileColor" content="#0969da">
|
||||||
|
|
||||||
|
<!-- App shortcuts for Chrome -->
|
||||||
|
<link rel="chrome-webstore-item" href="https://chrome.google.com/webstore/detail/abovethemark-gfm-editor">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="root"></div>
|
||||||
|
|
||||||
|
<!-- Load main.js from dist (already bundled) -->
|
||||||
|
<script type="module" src="/index.html"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
15
public/iwa/index.html
Normal file
15
public/iwa/index.html
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>AboveTheMark - GFM Editor</title>
|
||||||
|
<link rel="icon" type="image/svg+xml" href="../favicon.svg">
|
||||||
|
<meta name="theme-color" content="#0969da">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="root"></div>
|
||||||
|
<!-- Main app loads from index.html via module script -->
|
||||||
|
<script type="module" src="../index.html"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
20
public/iwa/manifest.json
Normal file
20
public/iwa/manifest.json
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"name": "AboveTheMark GFM Editor",
|
||||||
|
"short_name": "AboveTheMark",
|
||||||
|
"description": "GitHub Flavored Markdown editor with LaTeX, SVG, PDF and DOCX support",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"start_url": "../index.html",
|
||||||
|
"display": "standalone",
|
||||||
|
"default_locale": "en-US",
|
||||||
|
"installable": true,
|
||||||
|
"background_color": "#ffffff",
|
||||||
|
"theme_color": "#0969da",
|
||||||
|
"icons": [
|
||||||
|
{
|
||||||
|
"src": "favicon.svg",
|
||||||
|
"sizes": "any",
|
||||||
|
"type": "image/svg+xml",
|
||||||
|
"purpose": "any maskable"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -2,8 +2,9 @@ import { defineConfig } from 'vite';
|
|||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
import { viteSingleFile } from 'vite-plugin-singlefile';
|
import { viteSingleFile } from 'vite-plugin-singlefile';
|
||||||
|
|
||||||
// Set SINGLEFILE=1 to emit one self-contained index.html (all JS/CSS/fonts inlined).
|
// Build modes: single-file, iwa (Installer for Web Applications), or default/pwa
|
||||||
const singleFile = process.env.SINGLEFILE === '1';
|
const singleFile = process.env.SINGLEFILE === '1';
|
||||||
|
const iwaBuild = process.env.IWA === '1';
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react(), ...(singleFile ? [viteSingleFile()] : [])],
|
plugins: [react(), ...(singleFile ? [viteSingleFile()] : [])],
|
||||||
@@ -18,7 +19,7 @@ export default defineConfig({
|
|||||||
minify: 'terser',
|
minify: 'terser',
|
||||||
// Inline every asset (including KaTeX fonts) as data URIs for the single file.
|
// Inline every asset (including KaTeX fonts) as data URIs for the single file.
|
||||||
assetsInlineLimit: singleFile ? 100_000_000 : 4096,
|
assetsInlineLimit: singleFile ? 100_000_000 : 4096,
|
||||||
cssCodeSplit: !singleFile,
|
cssCodeSplit: !(singleFile || iwaBuild),
|
||||||
chunkSizeWarningLimit: singleFile ? 6000 : 500
|
chunkSizeWarningLimit: singleFile ? 6000 : 500
|
||||||
},
|
},
|
||||||
optimizeDeps: {
|
optimizeDeps: {
|
||||||
|
|||||||
Reference in New Issue
Block a user