All Projects → gobeli → eleventy-plugin-svelte

gobeli / eleventy-plugin-svelte

Licence: other
Eleventy plugin to support svelte templates

Programming Languages

javascript
184084 projects - #8 most used programming language
Svelte
593 projects
HTML
75241 projects

Projects that are alternatives of or similar to eleventy-plugin-svelte

eleventy-plugin-cloudinary
An Eleventy shortcode that allows you to add an image from your cloudinary account
Stars: ✭ 28 (-30%)
Mutual labels:  eleventy, 11ty, eleventy-plugin
eleventy-plugin-prismic
Eleventy plugin and shortcodes to fetch and present Prismic content
Stars: ✭ 39 (-2.5%)
Mutual labels:  eleventy, 11ty, eleventy-plugin
eleventy-plugin-social-images
Create dynamic images sized for social media tags for your Eleventy content.
Stars: ✭ 35 (-12.5%)
Mutual labels:  eleventy, eleventy-plugin
eleventy-plugin-unfurl
Unfurl links into rich cards, as seen in places like Slack and Twitter
Stars: ✭ 37 (-7.5%)
Mutual labels:  eleventy, eleventy-plugin
eleventy-plugin-embed-tweet
A plugin for embedding tweets on the server side during build time
Stars: ✭ 24 (-40%)
Mutual labels:  eleventy, eleventy-plugin
11ty-tailwind-jit
Try editing some Tailwind in this repo while running in dev. It's SO FAST!
Stars: ✭ 17 (-57.5%)
Mutual labels:  eleventy, 11ty
eleventy bundler
NOT RECOMMENDED FOR USE; see README
Stars: ✭ 19 (-52.5%)
Mutual labels:  eleventy, 11ty
eleventy-plugin-toc
11ty plugin to generate a TOC from page content
Stars: ✭ 45 (+12.5%)
Mutual labels:  eleventy, eleventy-plugin
fernfolio-11ty-template
The super simple portfolio template built with Eleventy and Netlify CMS
Stars: ✭ 64 (+60%)
Mutual labels:  eleventy, 11ty
11ty-sass-skeleton
Featuring absolutely nothing beyond a base HTML5 template and the essential setup to watch and compile your Sass alongside 11ty.
Stars: ✭ 174 (+335%)
Mutual labels:  eleventy, 11ty
eleventy-plugin-pwa
An eleventy plugin to generate service-worker for PWA. Powered by Google Workbox
Stars: ✭ 46 (+15%)
Mutual labels:  eleventy, eleventy-plugin
smol-11ty-starter
Extremely minimal Eleventy starter to kickstart a simple multi-page site / a nearly opinionless foundation to continue building on.
Stars: ✭ 61 (+52.5%)
Mutual labels:  eleventy, 11ty
eleventy-navigation
A plugin for creating hierarchical navigation in Eleventy projects. Supports breadcrumbs too!
Stars: ✭ 88 (+120%)
Mutual labels:  eleventy, eleventy-plugin
frontenso-11ty-starter
Production-ready 11ty+Gulp+Webpack Starter that features Nunjucks, SASS, TailwindCSS (with JIT complier), and ESNext.
Stars: ✭ 24 (-40%)
Mutual labels:  eleventy, 11ty
eleventy-plugin-inclusive-language
A linter plugin to check for inclusive language in markdown files.
Stars: ✭ 32 (-20%)
Mutual labels:  eleventy, eleventy-plugin
bymattlee-11ty-starter
A starter boilerplate powered by 11ty, Sanity, Gulp, Tailwind CSS, rollup.js, Alpine.js and Highway.
Stars: ✭ 27 (-32.5%)
Mutual labels:  eleventy, 11ty
htmlrecipes
A collection of quick copy HTML snippets for a variety of common scenarios.
Stars: ✭ 113 (+182.5%)
Mutual labels:  eleventy, 11ty
11up
A utility to create an 11ty site scaffold from one of a number of site templates. Mostly just Phil Hawksworth's regular starting points
Stars: ✭ 25 (-37.5%)
Mutual labels:  eleventy, 11ty
eleventy-upgrade-help
Helper plugin when upgrading your Eleventy project to a new major version.
Stars: ✭ 33 (-17.5%)
Mutual labels:  eleventy, eleventy-plugin
smix-eleventy-starter
A standards-respecting starter kit for Eleventy. Go Indie.
Stars: ✭ 108 (+170%)
Mutual labels:  eleventy, 11ty

npm npm

Eleventy Plugin to enable svelte

Heavily inspired by eleventy-plugin-vue.

Installation

npm install eleventy-plugin-svelte

  • Requires experimental features in Eleventy, specifically: Custom File Extension Handlers feature from Eleventy. Opt in to experimental features on Eleventy by running ELEVENTY_EXPERIMENTAL=true npx @11ty/eleventy.

Features

  • Builds *.svelte single file components.
  • Emits client side JavaScript code which can be included on the site to enable hydration of the static HTML.
  • Data which is defined in the data function (module context) feeds into the data cascade.
  • Data is supplied via Svelte props, to use the data during runtime you have to define a dataFn which defines what will be provided as props at runtime. (see example)

Not yet available

  • Svelte components as layouts

Usage

const eleventySvelte = require('eleventy-plugin-svelte')

module.exports = function (eleventyConfig) {
  // Use Defaults
  eleventyConfig.addPlugin(eleventySvelte)
}

Customize with options

const eleventySvelte = require('eleventy-plugin-svelte')

module.exports = function (eleventyConfig) {
  // Use Defaults
  eleventyConfig.addPlugin(eleventySvelte, {
    // Directory to emit client side JS code
    assetDir: 'assets',

    // If false client side bundle is not generated
    outputClient: true,

    // Options for the rollup-plugin-svelte for prerendering
    rollupPluginSvelteSSROptions: {},

    // Options for the rollup-plugin-svelte for the client side code
    rollupPluginSvelteClientOptions: {},

    // Additional rollup plugins for prerendering
    rollupSSRPlugins: [],

    // Additional rollup plugins for the client side code
    rollupClientPlugins: [],
  })
}

Example Configuration

const eleventySvelte = require('eleventy-plugin-svelte')
const postcss = require('rollup-plugin-postcss')
const terser = require('rollup-plugin-terser').terser

const dev = process.env.NODE_ENV === 'development'

// Example with prerendering the styles and omitting them in the client bundle.
module.exports = function (eleventyConfig) {
  eleventyConfig.addPlugin(eleventySvelte, {
    rollupSSRPlugins: [postcss()],
    rollupPluginSvelteClientOptions: {
      emitCss: false,
      compilerOptions: {
        css: false
      }
    },
    rollupClientPlugins: [!dev && terser()],
  })
}

Template Variables and Functions

<!DOCTYPE html>
<html lang="en">
  <head>
    ...
    <!-- Adds content from svelte:head -->
    {{ content.head | safe }}
    
    <!-- Adds prerendered css -->
    <style>
      {{ content.css | safe }}
    </style>
  </head>
  <body>
    ....
    <!-- Adds prerendered html -->
    {{ content | safe }}  
  </body>
  <script>
    // Provides the data used on the client side (dataFn is a function defining the used data)
    {{ dataFn | svelteData | safe }}
  </script>
  <!-- Gets the svelte client side code for browsers which support es modules ("app" is the id of the HTMLElement the app is going to mount on) -->
  {% svelteClient 'app' %}
  <!-- The legacy bundle needs systemjs to be loaded -->
  <script nomodule src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/6.3.2/s.min.js"></script>
  <!-- Gets the svelte client side code for browsers do not support es modules ("app" is the id of the HTMLElement the app is going to mount on) -->
  {% svelteClientLegacy 'app' %}
</html>
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].