Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/shalomscott/eleventy-plugin-embed-svelte

An Eleventy plugin that makes embedding Svelte components in your static pages painfully easy.
https://github.com/shalomscott/eleventy-plugin-embed-svelte

eleventy eleventy-plugin plugin svelte

Last synced: 3 months ago
JSON representation

An Eleventy plugin that makes embedding Svelte components in your static pages painfully easy.

Awesome Lists containing this project

README

        

# Eleventy Plugin Embed Svelte

> 🎉 Embed Svelte Components in Your 11ty Site! 🎉

## Example Usage

See the `example` directory for a complete example usage of this plugin.

**Check out the example live [here](https://shalomscott.github.io/eleventy-plugin-embed-svelte/) 👈**

## Installation

[Install the plugin](https://www.11ty.dev/docs/plugins/#adding-a-plugin) through npm:

```sh
npm install eleventy-plugin-embed-svelte
```

Then add it to your [Eleventy config](https://www.11ty.dev/docs/config/) file, like this:

```javascript
const embedSvelte = require('eleventy-plugin-embed-svelte');

module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(embedSvelte, {
// Directory that hosts your *.svelte component files (Optional)
svelteDir: './svelte',
// Pass options to rollup-plugin-svelte. (Optional)
rollupPluginSvelteOptions: { preprocess: sveltePreprocess() },
// Array of Rollup input plugins. (Optional)
rollupInputPlugins: [],
// Array of Rollup output plugins. (Optional)
rollupOutputPlugins: [terser()]
});

// Rest of config file...
};
```

## Usage

To embed Svelte components, all you need to do is use the shortcode `embedSvelte`.

### Example

#### `Greeter.svelte`

```svelte

export let user;

Hello there {user}!


```

#### `index.md`

```nunjucks
Here is our Greeter Svelte component, embedded right into this doc!

{% embedSvelte 'Greeter.svelte', { user: 'Zach Harris' } %}
```

**_It's as simple as that!_**

## Features

- A simple shortcode: `{% embedSvelte ... %}`, that allows you to easily embed any Svelte component and pass in `props`.
- An [Eleventy Transform](https://www.11ty.dev/docs/config/#transforms) that works behind the scenes to perform a Rollup build for each page with embedded Svelte components, and efficiently add the code to the output HTML.
- Adds the `svelteDir` (see plugin's options above) to Eleventy's list of [watch targets](https://www.11ty.dev/docs/config/#add-your-own-watch-targets).