All Projects → sveltejs → Svelte Preprocess

sveltejs / Svelte Preprocess

Licence: mit
A ✨ magical ✨ Svelte preprocessor with sensible defaults and support for: PostCSS, SCSS, Less, Stylus, Coffeescript, TypeScript, Pug and much more.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Svelte Preprocess

Sveltejs Forms
Declarative forms for Svelte
Stars: ✭ 163 (-83.2%)
Mutual labels:  hacktoberfest, svelte
Ajari Koding
📚 Kumpulan berbagai sumber daya untuk belajar koding dari hasil karya para kreator lokal yang terpercaya dan telah dikurasi oleh komunitas PHPID
Stars: ✭ 156 (-83.92%)
Mutual labels:  hacktoberfest, svelte
Svelte Firebase
A template to help you start developing SPAs with Svelte and Firebase.
Stars: ✭ 111 (-88.56%)
Mutual labels:  hacktoberfest, svelte
Wg Ui
WireGuard Web UI for self-serve client configurations, with optional auth.
Stars: ✭ 690 (-28.87%)
Mutual labels:  hacktoberfest, svelte
Svelte I18n
Internationalization library for Svelte
Stars: ✭ 433 (-55.36%)
Mutual labels:  hacktoberfest, svelte
Svelte Storybook Tailwind
A starter template for Svelte, TailwindCSS and Storybook. You can easily start your project with this template, instead of wasting time figuring out configurations for each integration.
Stars: ✭ 204 (-78.97%)
Mutual labels:  hacktoberfest, svelte
Musicplayer
A minimal music player built on electron.
Stars: ✭ 145 (-85.05%)
Mutual labels:  hacktoberfest, svelte
Parcel Plugin Svelte
A parcel plugin that enables svelte support
Stars: ✭ 214 (-77.94%)
Mutual labels:  hacktoberfest, svelte
Obs Web
OBS-web - the easiest way to control OBS remotely
Stars: ✭ 512 (-47.22%)
Mutual labels:  hacktoberfest, svelte
Revelt
Analysis of a project using React and Svelte technologies
Stars: ✭ 20 (-97.94%)
Mutual labels:  hacktoberfest, svelte
Wire Desktop
💻 Wire for desktop
Stars: ✭ 961 (-0.93%)
Mutual labels:  hacktoberfest
Bonita Doc
This repository contains the sources of the Bonita documentation site. It uses Markdown to create the documentation content.
Stars: ✭ 31 (-96.8%)
Mutual labels:  hacktoberfest
Training
Various Plone Trainings
Stars: ✭ 32 (-96.7%)
Mutual labels:  hacktoberfest
Neural Network From Scratch
Implementation of a neural network from scratch in python.
Stars: ✭ 32 (-96.7%)
Mutual labels:  hacktoberfest
App
The SimpleLogin back-end
Stars: ✭ 958 (-1.24%)
Mutual labels:  hacktoberfest
Laravel Guided Image
Simplified and ready image manipulation for Laravel through intervention image.
Stars: ✭ 32 (-96.7%)
Mutual labels:  hacktoberfest
Mod Pbxproj
A python module to manipulate XCode projects
Stars: ✭ 959 (-1.13%)
Mutual labels:  hacktoberfest
Ssh Agent Helper
Use SSH keys from CMD, PowerShell, etc. on Windows
Stars: ✭ 31 (-96.8%)
Mutual labels:  hacktoberfest
Calvin And Hobbes Quotes
🐯 Get Calvin and Hobbes quotes
Stars: ✭ 31 (-96.8%)
Mutual labels:  hacktoberfest
Codeclimate Fixme
A codeclimate engine for finding things you should fix.
Stars: ✭ 33 (-96.6%)
Mutual labels:  hacktoberfest

Svelte Preprocess

A Svelte preprocessor with sensible defaults and support for: PostCSS, SCSS, Less, Stylus, CoffeeScript, TypeScript, Pug and much more.

npm version license action-CI

What is it?

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.

import svelte from 'rollup-plugin-svelte'
import sveltePreprocess from 'svelte-preprocess'

export default {
  plugins: [
    svelte({
      preprocess: sveltePreprocess({ ... })
    })
  ]
}

Features

Template tag

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>

External files

<template src="./template.html"></template>
<script src="./script.js"></script>
<style src="./style.css"></style>

Global style

global attribute

Add 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 rule

Use 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.

Modern JavaScript syntax

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 preprocess from 'svelte-preprocess'
  ...
  preprocess: preprocess({
    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 values

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', 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}

Built-in support for commonly used languages

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>

Getting started

Preprocessing documentation

Usage documentation

Migration Guide


License

MIT

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].