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

pug-to-svelte

v1.1.0

Published

Pug to Svelte transpiler

Downloads

14

Readme


| | | 1. WHAT IS PUG-TO-SVELTE? | |_____________________________|

It lets you write Svelte components using Pug instead of vanilla HTML. In other words, it's a transpiler for Pug templates.

It's intended for use as part of the build process for Svelte applications, and aims to integrate Pug and Svelte smoothly without losing too much in the process.


| | | 2. PACKAGE STATUS | |_____________________|

COMPLETE --- the package has been used in production for multiple years, and requires no further development.


| | | 3. CAPABILITIES & LIMITATIONS | |_________________________________|

Capabilities:

  1. Converts Pug to HTML while preserving Svelte logic expressions and control structures.
  2. Supports all Svelte and Pug features except for those listed in "Limitations" below.
  3. Zero artificial syntax. All supported features use the same syntax as the respective features in Pug or Svelte.
  4. Can be combined with other transpilers (e.g. for scripts/styles) within the normal Svelte preprocessing workflow.
  5. Fast, lightweight, and efficient.

Limitations:

  1. Pug: NO spaces as indentation. Use tabs only.
  2. Pug: NO tags split across multiple lines. Each tag must be on a single line.
  3. Svelte: NO prop shorthands. For props with identical names and values, write both.
  4. Svelte: NO spread props.
  5. Svelte: NO style props.

| | | 4. EXAMPLE SYNTAX | |_____________________|

script. // import ... export let phaserSetting = 'stun' const shirtColor = '#FF0000' let powerLevel = 0

{#await startupEngines} EngineSpinner(speed='faster') {:then warpCoreStatus} {#if powerLevel > 9000} h1 Navigation plan: Andromeda Galaxy {#if warpCoreStatus.inRange} ol#galaxy-map {#each warpCoreStatus.reachablePlanets as planet} FastestRouteAnalysis(celestialBody={planet}) {:else} figure img(src='/public/space_hi_res_final.jpg') figcaption You stare out at a distant galaxy, unable to bridge the vastness of the universe. {:else} label(for='fusion-battery') Charge up the helium core! It's time to get going! input#fusion-battery(type='number' bind:value={powerLevel}) {:catch systemCrash} h1 Houston, we have a problem! .error-report | Computer says: {systemCrash.errorMessage} | Looks like we're not going to space today. button(on:click={systemCrash.moreMagic}) Maybe this will work? p Or how about starting a.extragalactic-link(href='https://svelte.dev/' target='_blank') a new galaxy?

style. .extragalactic-link { color: gold; } :global(#final-frontier) { background: var(--bg-full-of-stars); }


| | | 5. INSTALLATION & CONFIGURATION | |___________________________________|

Make sure to read the "Capabilities & Limitations" section to ensure that you are OK with the syntax restrictions listed.

  1. Install the 'pug-to-svelte' package from NPM. (Or, simply download and add the "index.js" file in this directory to your project.)
  2. Import the default export from the package (or file). This export is a function that transpiles Pug-based Svelte components into regular HTML-based Svelte components.
  3. Simply input Pug templates into the function and provide the output to the Svelte compiler (both as strings). It's recommended to set this up using Svelte's "preprocess" feature.

| | | 6. EXAMPLE CONFIGURATION (WEBPACK 5) | |________________________________________|

const pugToSvelte = require('pug-to-svelte')

module.exports = { module: { rules: [{ test: /.pug$/, use: [{ loader: 'svelte-loader', options: { preprocess: [{ markup: ({ content }) => ({ code: pugToSvelte(content) }) }] } }] }] } }