Registry / web-framework / pug-to-svelte

pug-to-svelte

JSON →
library1.1.0jsnpmunverified

Pug-to-Svelte transpiler (v1.1.0, stable, complete). Converts Pug templates to HTML while preserving Svelte logic, expressions, and control structures. Designed as a Svelte preprocessor. Key limitations: tabs-only indentation, no tag splitting across lines, no prop shorthands, no spread props, no style props. Production-ready and actively maintained but feature-complete. Faster and lighter than generic template transpilers, with zero artificial syntax.

npm install pug-to-svelte
INSTALL
IMPORT
SIG · PUG-TO-SVELTE
P
pug-to-svelte
web-frameworkjavascriptv1.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default export
import pugToSvelte from 'pug-to-svelte'
import { pugToSvelte } from 'pug-to-svelte'
Package exports a single function as default export. Named import will fail.
require
const pugToSvelte = require('pug-to-svelte')
const pugToSvelte = require('pug-to-svelte').default
CommonJS require works directly, no .default needed.
TypeScript types
import pugToSvelte from 'pug-to-svelte'
import pugToSvelte = require('pug-to-svelte')
Package ships TypeScript declarations. Use ESM import for proper type inference. For CJS, use const pugToSvelte: any = require('pug-to-svelte').

Transpile a simple Pug template to Svelte HTML, including error handling and integration with Svelte preprocessors.

import pugToSvelte from 'pug-to-svelte'; const pugCode = ` script. let count = 0 button(on:click={() => count++}) Clicked {count} times `; try { const htmlResult = pugToSvelte(pugCode); console.log(htmlResult); // Output: Svelte component with HTML } catch (error) { console.error('Transpilation failed:', error); } // Use with Svelte preprocessor: import { preprocess } from 'svelte/compiler'; import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'; const preprocessed = await preprocess( pugCode, vitePreprocess(), { filename: 'Component.svelte' } ); console.log(preprocessed.code);
Debug
Known issues
gotchaIndentation must use tabs only. Spaces as indentation will cause parse errors.
fix
Convert indentation to tabs. Most editors have a 'Convert Indentation to Tabs' option.
affects: >=1.0.0
gotchaTags cannot be split across multiple lines. Each tag must be on a single line.
fix
Ensure each tag (including attributes) is on one line.
affects: >=1.0.0
gotchaProp shorthands (e.g., `{value}` instead of `value={value}`) are NOT supported. Svelte-style shorthands like `{value}` will not work.
fix
Always explicitly write both prop name and value: `value={value}`.
affects: >=1.0.0
gotchaSpread props (e.g., `{...obj}`) are NOT supported.
fix
Expand props manually or use a wrapper component.
affects: >=1.0.0
gotchaStyle props (like `style:color`) are NOT supported.
fix
Use inline styles via the `style` attribute as an object string.
affects: >=1.0.0
deprecatedThis package is feature-complete and no further development is planned.
fix
No action needed, but evaluate if other transpilers (like svelte-preprocess with pug) suit your needs.
affects: >=1.1.0
Errors
Common errors & fixes
Error: Unexpected token 'div' at ...
Using spaces for indentation instead of tabs.
fix
Replace spaces with tabs for indentation in your .svelte files using Pug syntax.
Error: Expected newline or indentation but got something else at line X
A tag is split across multiple lines.
fix
Put the entire tag (including attributes) on a single line.
TypeError: pugToSvelte is not a function
Using named import instead of default import.
fix
Use `import pugToSvelte from 'pug-to-svelte'` or `const pugToSvelte = require('pug-to-svelte')`.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
pugrequiredPeer dependency for Pug template parsing.
Agent activity
2 hits · last 30 days
node
2
Resources
pug-to-svelte — npm install pug-to-svelte · libregistry