A template for creating Svelte applications powered by the Pear runtime, designed for building cross-platform desktop applications.
- Svelte: A modern, reactive framework for building user interfaces.
- Pear Runtime: P2P-ready runtime.
- Rollup: Creates bundles for development purposes.
- Testing: Includes
brittlefor testing. - File Watching: Automatically rebuilds bundles during development.
Setup Pear Open terminal to init where . is the directory you like to init the project to. Prefer cloning from GitHub for now (until a stable pear seed is available):
git clone https://github.com/zacharygriffee/svelte-pear-template.git my-new-app
cd my-new-app
npm installIf/when seeding is available, you can also init from the staged template:
pear init pear://8cnwqjydhcx6714sfty3kkdyracjng6ohwfmagxsixggcnnpskzo .svelte-pear/
├── app.js # Browser entry; loads Pear bridges and the bundled UI
├── dist/ # Bundled UI output consumed by app.js
│ └── entry.js # Rollup output (generated)
├── lib/ # Unbundled Pear-facing utilities (not bundled)
│ └── pear.js # Example Pear runtime helper
├── src/ # Svelte UI source code (bundled)
│ ├── entry.js # Rollup entry that exports mountApp
│ ├── App.svelte # Root Svelte component
│ └── lib/components/ # Svelte component library
│ └── Counter.svelte
├── test/ # Test files
│ └── index.test.js # Example test file
├── _template.json # Template JSON (specific to your app needs)
├── index.html # Main entry point for Pear (loads app.js)
├── package.json # Project configuration and dependencies
├── package-lock.json # Locked dependency versions
├── README.md # Project documentation
└── rollup.config.js # Rollup configuration file
$lib and $src similar to sveltekit alias work as expected for Svelte sources inside src/.
-
src/:- Bundled Svelte UI source.
entry.jsexportsmountApp, which is loaded dynamically.
- Bundled Svelte UI source.
-
dist/:- Rollup output produced by
npm run build;dist/entry.jsis required byapp.js.
- Rollup output produced by
-
lib/:- Unbundled Pear-facing scripts. Use this space for runtime bridges and pass them into Svelte via
app.js.
- Unbundled Pear-facing scripts. Use this space for runtime bridges and pass them into Svelte via
-
app.js:- Browser entry loaded by
index.html. Importsdist/entry.js, handslib/APIs into Svelte, and hooks Pear reloads.
- Browser entry loaded by
-
index.html:- Main entry point loaded by Pear and references
app.jsfor bootstrapping.
- Main entry point loaded by Pear and references
git clone https://github.com/zacharygriffee/svelte-pear-template.git my-new-app
cd my-new-appnpm installnpm run devThis script builds dist/entry.js and launches Pear via pear run -d .. Re-run after code changes or use the watch script during UI work:
npm run watch-buildProduction packaging for the Pear app is handled entirely by Pear. However, the dist/ directory will contain all the necessary assets for production once you're ready to package.
To prepare the dist/ directory:
npm run buildOnce the app is ready, Pear's built-in production packaging tools
The pear configuration is defined in package.json:
Read pear docs for more details.
"pear": {
"name": "svelte-pear",
"type": "desktop",
"gui": {
"backgroundColor": "#ffffff",
"height": 768,
"width": 1024
}
}name: Name of your Pear app.type: Specifies the app type (desktop).gui: Configures the appearance and dimensions of the app window.
| Script | Description |
|---|---|
npm run dev |
Builds dist/entry.js and runs Pear (pear run -d .). |
npm run build |
Generates the dist/ bundle from src/. |
npm run test |
Runs tests in the test/ directory using brittle. |
npm run watch-build |
Watches src/ for changes and rebuilds dist/. |
npm run watch-dev |
Cleans, rebuilds, runs Pear, then rebuilds on change. |
npm run dev-package |
Writes a local package.json with concrete Pear values (uses env overrides). |
npm run restore-template |
Restores the templated package.json from package.template.json. |
This template uses the brittle library for writing and running tests. Add test files in the test/ directory and run:
npm run testWhen the app is ready for production:
- Ensure the
dist/directory is complete and up-to-date by running:npm run build
- Use Pear’s production packaging tools to package the app: Read pear docs for more details.
- Your app at this point should be available for download via p2p pear link.
- Keep
package.jsontemplated when staging/publishing so_template.jsoncan inject values; runnpm run restore-templatebefore anypear stagecommands. - Links are derived from
pear.nameand channel; use the same name/channel to keep the same pear link across machines. - Typical flow from a clean checkout:
npm run restore-template && npm ci && npm run build && pear stage dev(orproduction), thenpear seed <channel>to share.
During template development, run:
npm run dev-packageThis writes a runnable package.json from the template, using defaults or environment variables:
APP_NAME=my-pear-app PEAR_HEIGHT=900 PEAR_WIDTH=1440 PEAR_LICENSE=MIT npm run dev-packageTo restore the untouched template:
npm run restore-templateThis template is licensed under the MIT License.