npm install svelte-preprocess
57.8
Supply Chain Risk
94.8
Quality
84.4
Maintenance
100
Vulnerability
1,748 Stars
660 Commits
150 Forks
18 Watching
10 Branches
72 Contributors
Updated on 09 Sept 2024
Minified
Minified + Gzipped
TypeScript (99.7%)
JavaScript (0.3%)
Cumulative downloads
Total Downloads
Last day
-30.1%
19,031
Compared to previous day
Last week
-4.9%
403,269
Compared to previous week
Last month
-4.4%
1,686,803
Compared to previous month
Last year
45.5%
18,144,361
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.
import { sveltePreprocess } from 'svelte-preprocess'; const config = { preprocess: sveltePreprocess({ ... }) } export default config;
Vue-like support for defining your markup between a specific tag. The default tag is template
but it can be customized.
<template> <div>Hey</div> </template> <style></style> <script></script>
<template src="./template.html"></template> <script src="./script.js"></script> <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.
<style global> div { color: red; } </style>
:global
ruleUse a :global
rule to only expose parts of the stylesheet:
<style lang="scss"> .scoped-style { } :global { @import 'global-stylesheet.scss'; .global-style { .global-child-style { } } } </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:
import { sveltePreprocess } from 'svelte-preprocess' ... preprocess: sveltePreprocess({ babel: { presets: [ [ '@babel/preset-env', { loose: true, // No need for babel to resolve modules modules: false, targets: { // ! Very important. Target es6+ esmodules: true, }, }, ], ], }, }); ...
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
:
autoPreprocess({ replace: [[/process\.env\.NODE_ENV/g, JSON.stringify(process.env.NODE_ENV)]], });
Which, in a production environment, would turn
{#if process.env.NODE_ENV !== 'development'} <h1>Production environment!</h1> {/if}
into
{#if 'production' !== 'development'} <h1>Production environment!</h1> {/if}
The current supported languages out-of-the-box are Sass, Stylus, Less, CoffeeScript, TypeScript, Pug, PostCSS, Babel.
<template lang="pug"> div Posts +each('posts as post') a(href="{post.url}") {post.title} </template> <script lang="ts"> export const hello: string = 'world'; </script> <style src="./style.scss"></style>
Reason
14 commit(s) and 15 issue activity found in the last 90 days -- score normalized to 10
Reason
license file detected
Details
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
4 existing vulnerabilities detected
Details
Reason
Found 12/30 approved changesets -- score normalized to 4
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
branch protection not enabled on development/release branches
Details
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
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-09-02
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 Moresvelte-preprocess-budoux
svelte-preprocess plugin for Budoux
mdx-svelte
MDX for Svelte. Svelte in Markdown. A Markdown preprocessor for Svelte. A Preprocessor for Svelte that allows you to write Svelte code inside Markdown files.
svelte-markdoc-preprocess
A Svelte preprocessor that allows you to use Markdoc.
svelte-jester
A Jest transformer for Svelte - compile your components before importing them into tests