A template for creating Svelte applications powered by the Pear runtime, designed for building cross-platform desktop applications.
brittle for testing.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 install
If/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/:
entry.js exports mountApp, which is loaded dynamically.dist/:
npm run build; dist/entry.js is required by app.js.lib/:
app.js.app.js:
index.html. Imports dist/entry.js, hands lib/ APIs into Svelte, and hooks Pear reloads.index.html:
app.js for bootstrapping.git clone https://github.com/zacharygriffee/svelte-pear-template.git my-new-app
cd my-new-app
npm install
npm run dev
This 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-build
Production 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 build
Once 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 test
When the app is ready for production:
dist/ directory is complete and up-to-date by running:npm run build
package.json templated when staging/publishing so _template.json can inject values; run npm run restore-template before any pear stage commands.pear.name and channel; use the same name/channel to keep the same pear link across machines.npm run restore-template && npm ci && npm run build && pear stage dev (or production), then pear seed <channel> to share.During template development, run:
npm run dev-package
This 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-package
To restore the untouched template:
npm run restore-template
This template is licensed under the MIT License.