Gathering detailed insights and metrics for svelte-preprocess
Gathering detailed insights and metrics for svelte-preprocess
Gathering detailed insights and metrics for svelte-preprocess
Gathering detailed insights and metrics for svelte-preprocess
A ✨ magical ✨ Svelte preprocessor with sensible defaults and support for: PostCSS, SCSS, Less, Stylus, Coffeescript, TypeScript, Pug and much more.
npm install svelte-preprocess
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (99.7%)
JavaScript (0.3%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
1,776 Stars
664 Commits
148 Forks
17 Watchers
10 Branches
70 Contributors
Updated on Jul 07, 2025
Latest Version
6.0.3
Package Id
svelte-preprocess@6.0.3
Unpacked Size
94.88 kB
Size
21.25 kB
File Count
65
NPM Version
10.1.0
Node Version
20.8.1
Published on
Sep 26, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
11
27
A Svelte preprocessor with sensible defaults and support for: PostCSS, SCSS, Less, Stylus, CoffeeScript, TypeScript, Pug and much more.
Svelte
's own parser understands only JavaScript, CSS and its HTML-like syntax. To make it possible to write components in other languages, such as TypeScript or SCSS, Svelte
provides the preprocess API, which allows to easily transform the content of your markup
and your style
/script
tags.
Writing your own preprocessor for, i.e SCSS is easy enough, but it can be cumbersome to have to always configure multiple preprocessors for the languages you'll be using.
svelte-preprocess
is a custom svelte preprocessor that acts as a facilitator to use other languages with Svelte, providing multiple features, sensible defaults and a less noisy development experience.
It is recommended to use with svelte.config.js
file, located at the project root. For other usage, please refer to usage documentation.
1import { sveltePreprocess } from 'svelte-preprocess'; 2 3const config = { 4 preprocess: sveltePreprocess({ ... }) 5} 6 7export default config;
Vue-like support for defining your markup between a specific tag. The default tag is template
but it can be customized.
1<template> 2 <div>Hey</div> 3</template> 4 5<style></style> 6 7<script></script>
1<template src="./template.html"></template> 2<script src="./script.js"></script> 3<style src="./style.css"></style>
Note: using a relative path starting with
.
is important. Otherwisesvelte-preprocess
will ignore thesrc
attribute.
global
attributeAdd a global
attribute to your style
tag and instead of scoping the CSS, all of its content will be interpreted as global style.
1<style global> 2 div { 3 color: red; 4 } 5</style>
:global
ruleUse a :global
rule to only expose parts of the stylesheet:
1<style lang="scss"> 2 .scoped-style { 3 } 4 5 :global { 6 @import 'global-stylesheet.scss'; 7 8 .global-style { 9 .global-child-style { 10 } 11 } 12 } 13</style>
Works best with nesting-enabled CSS preprocessors, but regular CSS selectors like div :global .global1 .global2
are also supported.
Note: needs PostCSS to be installed.
svelte-preprocess
allows you to run your component code through Babel before sending it to the compiler, allowing you to use new language features such as optional operators and nullish coalescing. However, note that Babel should transpile your component code to the javascript version supported by the Svelte compiler, so ES6+.
For example, with @babel/preset-env
your config could be:
1import { sveltePreprocess } from 'svelte-preprocess' 2 ... 3 preprocess: sveltePreprocess({ 4 babel: { 5 presets: [ 6 [ 7 '@babel/preset-env', 8 { 9 loose: true, 10 // No need for babel to resolve modules 11 modules: false, 12 targets: { 13 // ! Very important. Target es6+ 14 esmodules: true, 15 }, 16 }, 17 ], 18 ], 19 }, 20 }); 21 ...
Note: If you want to transpile your app to be supported in older browsers, you must run babel from the context of your bundler.
Replace a set of string patterns in your components markup by passing an array of [RegExp, ReplaceFn | string]
, the same arguments received by the String.prototype.replace
method.
In example, to replace inject the value of process.env.NODE_ENV
:
1autoPreprocess({
2 replace: [[/process\.env\.NODE_ENV/g, JSON.stringify(process.env.NODE_ENV)]],
3});
Which, in a production environment, would turn
1{#if process.env.NODE_ENV !== 'development'} 2 <h1>Production environment!</h1> 3{/if}
into
1{#if 'production' !== 'development'} 2 <h1>Production environment!</h1> 3{/if}
The current supported languages out-of-the-box are Sass, Stylus, Less, CoffeeScript, TypeScript, Pug, PostCSS, Babel.
1<template lang="pug"> 2 div Posts +each('posts as post') a(href="{post.url}") {post.title} 3</template> 4 5<script lang="ts"> 6 export const hello: string = 'world'; 7</script> 8 9<style src="./style.scss"></style>
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 11/30 approved changesets -- score normalized to 3
Reason
0 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 1
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
19 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More