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

@danielschischkin/publish-svelte

v0.8.1

Published

A command-line tool for publishing svelte components to npm

Downloads

7

Readme

publish-svelte

publish-svelte or "pelte" is a cli tool to easily compile, bundle and publish svelte components to npm. The bundle will contain both svelte files and vanilla js files, so the components can run "everywhere" no matter the framework. A readme file will also be published to npm, which will describe how to use the component.

"pelte" is optimal if you have an existing svelte project and you quickly want to share one of your components with the world. You don't need to extract the component from your project and fiddle with npm link and import statements.

Installation

npm install -g publish-svelte

Usage

Publish your svelte component to npm:

pelte ./MySvelteComponent.svelte

This will automatically compile, bundle and publish to npm. The first time you publish a component, "pelte" will be ask for a name and a version. You can just press enter if you like the suggestions.

"pelte" will create two files MySvelteComponent.md and MySvelteComponent.json. In the md-file you can describe your component and in the json-file you can change the name, version and more.

You can also increment the package version with patch, minor or major. Here the component is published with a patched version:

pelte ./MySvelteComponent.svelte --patch

Where is the bundle?

The bundle is removed after publish. You can examine the bundle without publishing to npm with:

pelte ./MySvelteComponent.svelte --skip-publish --keep-bundle

"--skip-publish" to skip publishing to npm and "--keep-bundle" will keep the bundle files which are otherwise cleaned.

For instance, you can open the index-example-umd.html and see your component in action.

Custom Elements (aka web components)

Pelte will automatically create a web component if your svelte component contains this line:

<svelte:options tag="my-svelte-component"/>

Then you can use the web component like this:

<body>
    <my-svelte-component></my-svelte-component>
</body>

You can read more on the official svelte page svelte page

Programmatic Usage

In rare cases, you might want to run pelte programmatically.

const { pelte } = require('publish-svelte');

const options = {
  srcFile: __dirname + '/Simple.svelte',
  keepBundle: true,
  skipPublish: true
}

pelte(options)

Pelte also exports a generate function that will generate bundles in-memory, but not write them to a file. This can be used if you want fine-grained control of the output bundle.

Note: The keepBundle and skipPublish options are ignored by generate

const { generate } = require('publish-svelte');

const options = {
  srcFile: __dirname + '/Simple.svelte',
}

generate(options).then(bundles => {
  const umd = bundles.find(bundle => bundle.options.format === 'umd')
  console.log('this is the umd bundle', umd)
})

Help?

See other available arguments with:

pelte ./MySvelteComponent.svelte --help

FEATURES COMING SOON:

Soon I will add some other features:

  • Better typescript support. There is some support but I have not tested more complex svelte components.
  • A react adapter should be included. Likely by using svelte adapter
  • Autogenerated typescript
  • Angular adapter. If possible?
  • Third party dependencies are added as optional dependencies. This is required for when a svelte project imports a pelte package.