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

preact-vite-app

v1.0.0

Published

A Preact app built with Vite

Downloads

17

Readme

To build a Vite-based Preact app as an npm package, you need to set up a project structure that includes the Vite configuration files, Preact placeholder code, and other necessary files. Below is the complete file structure, configuration, and placeholder code required to get you started.

1. Project Structure

Here's the basic structure of your Preact Vite project:

preact-vite-app/
├── public/
│   └── index.html
├── src/
│   ├── components/
│   │   └── App.jsx
│   ├── main.jsx
│   └── index.css
├── .gitignore
├── index.js
├── package.json
├── vite.config.js
└── README.md

2. Package Configuration

package.json

{
  "name": "preact-vite-app",
  "version": "1.0.0",
  "description": "A Preact app built with Vite",
  "main": "index.js",
  "module": "dist/index.js",
  "files": [
    "dist"
  ],
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview"
  },
  "dependencies": {
    "preact": "^10.0.0"
  },
  "devDependencies": {
    "@vitejs/plugin-react": "^3.0.0",
    "vite": "^4.0.0"
  }
}

3. Vite Configuration

vite.config.js

import { defineConfig } from 'vite';
import preact from '@vitejs/plugin-react';

export default defineConfig({
  plugins: [preact()],
  build: {
    lib: {
      entry: 'src/main.jsx',
      name: 'PreactViteApp',
      fileName: (format) => `preact-vite-app.${format}.js`,
    },
    rollupOptions: {
      external: ['preact'],
      output: {
        globals: {
          preact: 'Preact',
        },
      },
    },
  },
});

4. Source Code

public/index.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Preact Vite App</title>
</head>
<body>
  <div id="app"></div>
  <script type="module" src="/src/main.jsx"></script>
</body>
</html>

src/main.jsx

import { render } from 'preact';
import App from './components/App';
import './index.css';

render(<App />, document.getElementById('app'));

src/components/App.jsx

import { h } from 'preact';

function App() {
  return (
    <div>
      <h1>Hello, Preact + Vite!</h1>
    </div>
  );
}

export default App;

src/index.css

body {
  font-family: Arial, sans-serif;
  margin: 0;
  padding: 0;
  background-color: #f0f0f0;
  color: #333;
}

h1 {
  text-align: center;
  margin-top: 20%;
}

5. Entrypoint for the NPM Package

index.js

import App from './src/components/App';

export default App;

6. Git Ignore File

.gitignore

node_modules/
dist/
.vite/

7. README File

README.md

# Preact Vite App

This is a simple Preact app built with Vite, intended to be used as an npm package.

## Development

To start the development server:

```bash
npm run dev

Build

To build the project:

npm run build

Preview

To preview the built project:

npm run preview

Usage

After building, you can import the package in your project:

import PreactViteApp from 'preact-vite-app';

### 8. **Running the Project**

To run the project locally:

1. **Install Dependencies**:
   ```bash
   npm install
  1. Run Development Server:

    npm run dev
  2. Build the Project:

    npm run build

This will create a dist/ directory with your library that can be published to npm.

9. Publishing to NPM

To publish your package:

  1. Build the package:

    npm run build
  2. Log in to npm:

    npm login
  3. Publish the package:

    npm publish

This setup will give you a basic Vite + Preact app that can be easily developed and published as an npm package.