npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

astro-electron-ts

v1.0.26

Published

Build cross-platform desktop apps with Electron and Astro

Downloads

1,391

Readme

🚀 astro-electron-ts

Build cross-platform desktop applications with Astro and Electron. This integration seamlessly incorporates Electron into your Astro projects, handling all the setup and configuration automatically so you can focus on building your app.

preview

✨ Features

  • 🔌 Easy integration of Electron with Astro projects
  • ⚡️ Automatic CLI setup and configuration
  • ⚙️ Customizable Electron configuration with defaults
  • 🛠️ Support for both new projects and existing Astro projects

🤔 Why astro-electron-ts?

  • Actively maintained by the community and aim to support latest Electron versions and Astro
  • Supports both TypeScript and JavaScript out of the box
  • I aim to fix and close any issues as soon as possible

📦 Quick Start

Manual Installation (Recommended)

If you prefer to set things up manually, follow these steps:

  1. Install the dependencies:
<package-manager> add astro-electron-ts electron
  1. Add the integration to your astro.config.ts:
import { defineConfig } from 'astro/config';
import electron from 'astro-electron-ts';

export default defineConfig({
  integrations: [electron()],
});
  1. Add the entry point to your package.json:
{
  "main": "dist-electron/main.js"
}
  1. Add to your .gitignore:
# Electron
dist-electron/
  1. Create electron files:
// electron/main.ts
import { app, BrowserWindow } from 'electron';
import { fileURLToPath } from 'node:url';
import path from 'node:path';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

process.env.APP_ROOT = path.join(__dirname, '..');

export const VITE_DEV_SERVER_URL = process.env['VITE_DEV_SERVER_URL'];
export const MAIN_DIST = path.join(process.env.APP_ROOT, 'dist-electron');
export const RENDERER_DIST = path.join(process.env.APP_ROOT, 'dist');

process.env.VITE_PUBLIC = VITE_DEV_SERVER_URL
  ? path.join(process.env.APP_ROOT, 'public')
  : RENDERER_DIST;

let win: BrowserWindow | null;

function createWindow() {
  win = new BrowserWindow({
    width: 1000,
    height: 800,
    webPreferences: {
      preload: path.join(__dirname, 'preload.mjs'),
    },
  });

  // Test active push message to Renderer-process.
  win.webContents.on('did-finish-load', () => {
    win?.webContents.send('main-process-message', new Date().toLocaleString());
  });

  if (VITE_DEV_SERVER_URL) {
    win.loadURL(VITE_DEV_SERVER_URL);
  } else {
    win.loadFile(path.join(RENDERER_DIST, 'index.html'));
  }
}

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit();
    win = null;
  }
});

app.on('activate', () => {
  if (BrowserWindow.getAllWindows().length === 0) {
    createWindow();
  }
});

app.whenReady().then(createWindow);
// electron/preload.ts
console.log('preload.ts');

Using the CLI (Unstable)

The easiest way to get started is by using our CLI. But beware: The CLI is really new and is massively being worked on, so it might be unstable or not work at all and probably have bugs.

Steps:

# You run the same command for both new and existing projects
npx astro-electron-ts@latest

The CLI will:

  1. Auto-detect your project setup
  2. Install necessary dependencies using your preferred package manager
  3. Add required configuration files
  4. Set up Electron with TypeScript support

⚙️ Configuration

Customize your Electron setup with these configuration options:

export default defineConfig({
  integrations: [
    electron({
      main: {
        entry: 'electron/main.ts', // Path to your Electron main file
        vite: {}, // Vite-specific configurations
      },
      preload: {
        input: 'electron/preload.ts', // Path to your Electron preload file
        vite: {}, // Vite-specific configurations
      },
      renderer: {
        // Renderer-specific configurations
      },
    }),
  ],
});

For more configuration options, check out the vite-plugin-electron docs 📚

🎨 Static Assets

To use static assets (fonts, videos, etc.) in your Electron app:

  • Use the /public directory in your paths explicitly
  • For images, use Image from astro:assets

🏗️ Building and Publishing

While this integration focuses on development setup, we recommend using Electron Forge for building and publishing your app.

📄 License

MIT License - do whatever you want with it! 🎉