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

esbuild-svelte5

v0.8.5

Published

esbuild plugin to resolve .svelte files with support for Svelte 5

Downloads

201

Readme

esbuild-svelte

npm version npm downloads CI

Plugin to compile svelte components for bundling with esbuild.

Install

Install this plugin, esbuild and Svelte.

A simple build script looks like

import esbuild from "esbuild";
import sveltePlugin from "esbuild-svelte";

esbuild
  .build({
    entryPoints: ["app.js"],
    mainFields: ["svelte", "browser", "module", "main"],
    conditions: ["svelte", "browser"],
    bundle: true,
    outfile: "out.js",
    plugins: [sveltePlugin()],
    logLevel: "info",
  })
  .catch(() => process.exit(1));

The example-js folder of this repository is a great starting off point for a "complete" project. You can quickly get started using degit:

# Clone the JavaScript example to get started
npx degit EMH333/esbuild-svelte/example-js my-svelte-app

# Clone the TypeScript example to get started
npx degit EMH333/esbuild-svelte/example-ts my-svelte-app

CSS Output

By default, esbuild-svelte emits external css files from Svelte for esbuild to process. If this isn't desired, use a configuration that turns off external css output and instead includes it in the javascript output. For example: sveltePlugin({compilerOptions: {css: true}})

Typescript and Other Svelte Preprocessing

In order to support Typescript and other languages that require preprocessing before being fed into the Svelte compiler, simply add the preprocessor to the preprocess option (which accepts both a single preprocessor or an array of them). The example script below is a great place to start, you can also look at the example-ts folder for a more complete project.

import esbuild from "esbuild";
import esbuildSvelte from "esbuild-svelte";
import sveltePreprocess from "svelte-preprocess";

esbuild
  .build({
    entryPoints: ["index.js"],
    mainFields: ["svelte", "browser", "module", "main"],
    conditions: ["svelte", "browser"],
    bundle: true,
    outdir: "./dist",
    plugins: [
      esbuildSvelte({
        preprocess: sveltePreprocess(),
      }),
    ],
  })
  .catch(() => process.exit(1));

svelte exports condition

If you are importing a svelte component library, you need to add "svelte" to conditions in esbuild build options. This lets esbuild use the svelte property in svelte component's exports conditions in package.json .

Advanced

For incremental or watch build modes, esbuild-svelte will automatically cache files if they haven't changed. This allows esbuild to skip the Svelte compiler for those files altogether, saving time. Setting cache: false will disable this file level cache if an issue arises (please report).

You can see the full API for this plugin here, which includes support for Svelte's compiler options, preprocessing API, and more.

Developing

Clone, npm install, npm link and it's good to go! Releases are automated (with the right permissions), just by running npm version patch|minor|major.