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

docusaurus-plugin-svelte

v0.1.8

Published

Docusaurus (v2) loads content from user friendly mdx files and converts the mdx files to html files.

Downloads

2

Readme

Docusaurus Plugin to embed svelte components

Docusaurus (v2) loads content from user friendly mdx files and converts the mdx files to html files.

This plugin - docusaurus-plugin-svelte helps docusaurus understand .svelte files so the components in the .svelte files could be rendered directly inline in the .mdx file.

Usage

Dependency in package.json

In the project created by docusaurus - modify the package.json to add the following new dependency In package.json as the following

package.json

   "dependencies": {
       "docusaurus-plugin-svelte": "^0.1.7"
    }

The peerDependencies - svelte and svelte-loader also needs to be installed as above so as to not pollute the namespace of the dependent projects.

Configuring docusaurus to add the plugin

After adding the new dependency as mentioned above - make changes to the docusaurus config file - <project root>/docusaurus.config.js as below by adding to plugins property as below.

<project root>/docusaurus.config.js


export default { 

 plugins: [
    "docusaurus-plugin-svelte"
  ],
  presets: [


  ]
}

The plugin should help enable docusaurus to read the .svelte files in the content repository and inject them into the components.

Example

Docusaurus v2, depends on mdx v1 - hence it supports cjs and does not support esm natively yet.

mdx v2 does support them natively thoough.

Due to that limitation, we use an adapter react component to embed our svelte component until then.

Dependency

We use the external library svelte-adapter to embed our svelte component inside a react component to make things work.

We add the dependency to package.json as below.

package.json


"dependencies": {
    
    "svelte-adapter": "^0.5.0",
    
}

Svelte component

Say - we have a svelte component - hello.svelte as below.

hello.svelte

<div class="nice">
  A nice hello universe component
</div>
<style>
.nice {
    background: purple;
    padding: 2rem 2rem 2rem 2rem;
}    
</style>

Content / mdx file

The above mentioned svelte component can be embeeded in a mdx file as below.

content.mdx


## Embedding svelte inside a mdx file

The following content renders the svelte component - hello.svelte below.

import toReact from "svelte-adapter/react";
import hello from './hello.svelte';

export const baseStyle = {
  width: "100%"
};

export const HelloUniverse = toReact(hello, baseStyle, "div");


<HelloUniverse />