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

@alanlyc/svelte5-tailwind-scaffolding

v0.0.18

Published

This is just a simple package to bootstrap my personal projects with Svelte 5 and TailwindCSS. Nothing special.

Downloads

19

Readme

svelte5-tailwind-scaffolding

This is just a simple package to bootstrap my personal projects with Svelte 5 and TailwindCSS. Nothing special.

It provides functions for displaying modals and it displays error automatically. There are also utilities for buttons, input, and autocompleted input. It also automatically apply bg-neutral-900 and text-white to body in dark mode.

Browser Requirements

  1. modal, modal.builder, block, and BaseModal requires HTMLDialogElement (Baseline 2022) and the CSS *-inline-start, *-inline-end family of properties (Baseline 2020)
  2. Autocomplete.autoselect requires the CSS :has() selector
  3. Table requires the CSS *-inline-start, *-inline-end family of properties

Setup

1. Install Everything

npm create svelte@latest   # select Svelte 5
npm i
npm install -D tailwindcss postcss autoprefixer && npx tailwindcss init -p
npm i @alanlyc/svelte5-tailwind-scaffolding

2. tailwind.config.js

/** @type {import('tailwindcss').Config} */
export default {
    content: ['./src/**/*.{html,js,svelte,ts}'],
    theme: {
        extend: {},
    },
    plugins: [],
    darkMode: "class",  // <-- this is required
}

3. src/app.html

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <link rel="icon" href="%sveltekit.assets%/favicon.png" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        %sveltekit.head%
        <script>
            if (
                window.matchMedia('prefers-color-scheme: dark') ||
                localStorage.getItem('theme') === 'dark'
            )
                document.documentElement.classList.add('dark');
            if (localStorage.getItem('theme') === 'light')
                document.documentElement.classList.remove('dark');
        </script>
    </head>
    <body data-sveltekit-preload-data="hover">
        <div style="display: contents">%sveltekit.body%</div>
    </body>
</html>

4. src/app.css

@tailwind base;
@tailwind components;
@tailwind utilities;

5. src/routes/+layout.svelte

<script lang="ts">
    import { Scaffolding } from "@alanlyc/svelte5-tailwind-scaffolding"
	import '../app.css'
</script>

<Scaffolding />

<slot />

6. src/routes/+page.svelte

<script lang="ts">
    import { modal, Button } from "@alanlyc/svelte5-tailwind-scaffolding"
</script>

<Button class="block" onclick={async () => {
    // most part of the modal was designed by Tailwind UI
    // but dark mode was added by me
    await modal({
        type: "ok",
        title: "Congratulations!",
        md: "You have completed setting up the scaffolding!",
        actions: ["OK"],
		defaultReturn: undefined,
    })
}}>
    OK Modal
</Button>

7. npm run dev

When you click the button, you may encounter a Vite optimization and see a hydration error. It should be fine to just wait for it to reload.

Bonus: cloudflare

Since setting up Cloudflare + SvelteKit for development is a hassle, I will just add a section here on how to setup Cloudflare development environment (only partially tested as of right now).

1. Install Everything

npm i -D @cloudflare/workers-types @sveltejs/adapter-cloudflare miniflare

2. src/hooks.server.ts

import { dev } from "$app/environment";
import type { Miniflare } from "miniflare";

let mf: Miniflare;

export async function handle({ event, resolve }) {
    if (dev) {
        if (!mf) {
            const { Miniflare, Log, LogLevel } = await import("miniflare");
            mf = new Miniflare({
                log: new Log(LogLevel.INFO),
                kvPersist: ".wrangler/state/v3/kv",
                kvNamespaces: ["KV"],
                r2Persist: ".wrangler/state/v3/r2",
                r2Buckets: ["RV"],
                // ... and whatever bindings you have
                script: "",
                modules: true,
            });
        }
        event.platform = { env: await mf.getBindings() };
    }
    return resolve(event);
}

3. src/app.d.ts

import type { KVNamespace, R2Bucket } from "@cloudflare/workers-types";

// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
declare global {
    namespace App {
        // interface Error {}
        // interface Locals {}
        // interface PageData {}
        // interface PageState {}
        interface Platform {
            env: {
                KV: KVNamespace,
                R2: R2Bucket,
            }
        }
    }
}

export {};

4. wrangler.toml

You don't actually have to put any config here for development.

name = "<insert_app_name>"
compatibility_date = "<insert_today_YYYY-MM-DD>"

5. npm run dev

If vite is trying to optimize miniflare, configure vite.config.ts as follow:

import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vitest/config';

export default defineConfig({
    plugins: [sveltekit()],
    test: {
        include: ['src/**/*.{test,spec}.{js,ts}']
    },
    optimizeDeps: {
        exclude: ['miniflare']
    }
});

6. Interact with bindings with Wrangler

Interact with KV:

# notice that we use --namespace-id, not --bindings (which is used if we actually use wrangler.toml)
npx wrangler kv:key put abcxyz "https://google.com" --namespace-id KV --local