You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+10-10Lines changed: 10 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Svelte Preprocess
2
2
3
-
> A [Svelte](https://svelte.dev) preprocessor with sensible defaults and support for: PostCSS, SCSS, Less, Stylus, Coffeescript, TypeScript, Pug and much more.
3
+
> A [Svelte](https://svelte.dev) preprocessor with sensible defaults and support for: PostCSS, SCSS, Less, Stylus, CoffeeScript, TypeScript, Pug and much more.
-[Built-in support for commonly used languages](#built-in-support-for-commonly-used-languages)
31
31
32
32
## What is it?
33
33
34
-
`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](https://svelte.dev/docs#svelte_preprocess), which allows to easily transform the content of your `markup` and your `style`/`script` tags.
34
+
`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](https://svelte.dev/docs#svelte_preprocess), which allows to easily transform the content of your `markup` and your `style`/`script` tags.
35
35
36
-
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.
36
+
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.
37
37
38
38
`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.
39
39
40
40
```js
41
41
importsveltefrom'rollup-plugin-svelte'
42
-
importsveltePreprocessfrom'svelte-preprocess'
42
+
importautoPreprocessfrom'svelte-preprocess'
43
43
44
44
exportdefault {
45
45
plugins: [
46
46
svelte({
47
-
preprocess:sveltePreprocess({ ... })
47
+
preprocess:autoPreprocess({ ... })
48
48
})
49
49
]
50
50
}
@@ -114,9 +114,9 @@ Works best with nesting-enabled CSS preprocessors, but regular CSS selectors lik
114
114
115
115
_**Note**: needs PostCSS to be installed._
116
116
117
-
### Modern Javascript syntax
117
+
### Modern JavaScript syntax
118
118
119
-
`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+.
119
+
`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+.
120
120
121
121
For example, with `@babel/preset-env` your config could be:
122
122
@@ -153,7 +153,7 @@ Replace a set of string patterns in your components markup by passing an array o
153
153
In example, to replace inject the value of `process.env.NODE_ENV`:
-Sass: `npm install -D node-sass` or `npm install -D sass`
35
+
-Pug: `npm install -D pug`
36
+
-Stylus: `npm install -D stylus`
37
37
38
38
For now, let's just install the main library.
39
39
@@ -70,21 +70,21 @@ export default {
70
70
}
71
71
```
72
72
73
-
Now our app's code can be written in any of the syntaxes supported by `svelte-preprocess`: `SCSS`, `Stylus`, `Less`, `Coffeescript`, `TypeScript`, `Pug`, `PostCSS`, `Babel`.
73
+
Now our app's code can be written in any of the syntaxes supported by `svelte-preprocess`: Sass, Stylus, Less, CoffeeScript, TypeScript, Pug, PostCSS, Babel.
74
74
75
75
_**Note:** If you use VS Code, check [its usage guide](/docs/usage.md#with-svelte-vs-code) to make the Svelte VS Code extension understand the content of your components._
76
76
77
77
## 3. Configuring preprocessors
78
78
79
-
Now let's assume our app markup is going to be written in `pug`, our scripts in `Typescript`, and our styles in `SCSS`. We also want our styles to be auto-prefixed, so we're also going to need `postcss`. Let's install these dependencies:
79
+
Now let's assume our app markup is going to be written in Pug, our scripts in TypeScript, and our styles in Sass. We also want our styles to be auto-prefixed, so we're also going to need PostCSS. Let's install these dependencies:
80
80
81
-
**Important:**`svelte-preprocess` only handles content passed to it by `svelte-loader`, `rollup-plugin-svelte` and similar tools. If our `typescript` component import a `typescript` file, the bundler will be the one responsible for handling it. We must make sure it knows how to handle it!
81
+
**Important:**`svelte-preprocess` only handles content passed to it by `svelte-loader`, `rollup-plugin-svelte` and similar tools. If our TypeScript component import a TypeScript file, the bundler will be the one responsible for handling it. We must make sure it knows how to handle it!
82
82
83
83
```shell
84
84
$ npm i -D typescript sass postcss autoprefixer pug @rollup/plugin-typescript
85
85
```
86
86
87
-
After the installation is complete, we still need to configure our `postcss` options and add `@rollup/plugin-typescript` to our config.
87
+
After the installation is complete, we still need to configure our PostCSS options and add `@rollup/plugin-typescript` to our config.
88
88
89
89
```diff
90
90
import svelte from 'rollup-plugin-svelte'
@@ -143,7 +143,7 @@ And we're done! Our components can now be written as:
143
143
144
144
### 3.1. Setting default languages
145
145
146
-
Ok, we now can write our entire app with `pug`, `typescript` and `scss`, but typing `lang="..."` in every file can become an obnoxious process. In [auto-preprocessing mode](/docs/preprocessing.md#auto-preprocessing), `svelte-preprocess`[lets us define the default languages](/docs/preprocessing.md#auto-preprocessing-options) of our components. It's setted by default to `html`, `javascript` and `css`. Let's change that so we don't need those `lang` attributes.
146
+
Ok, we now can write our entire app with Pug, TypeScript and SCSS, but typing `lang="..."` in every file can become an obnoxious process. In [auto-preprocessing mode](/docs/preprocessing.md#auto-preprocessing), `svelte-preprocess`[lets us define the default languages](/docs/preprocessing.md#auto-preprocessing-options) of our components. It's setted by default to HTML, JavaScript and CSS. Let's change that so we don't need those `lang` attributes.
147
147
148
148
_**Disclaimer**: The Svelte VS Code extension uses the `lang` or `type` attribute to correctly highlight your code. At the time of writing, the extension doesn't support default languages. Doing this can lead to errors on your IDE._
149
149
@@ -202,18 +202,18 @@ Now our components are a bit leaner!
202
202
</style>
203
203
```
204
204
205
-
_**Note**: If the `<template>` tag is not found and the default language is not `html`, `svelte-preprocess` expects the whole markup to be written in that language. In example, for `pug`, this means the `script` and `style` tags must be written following pug's syntax._
205
+
_**Note**: If the `<template>` tag is not found and the default language is not HTML, `svelte-preprocess` expects the whole markup to be written in that language. In example, for Pug, this means the `script` and `style` tags must be written following pug's syntax._
206
206
207
207
### 3.2 Prepending content
208
208
209
-
Now we're in need of a `scss` file to hold some variables. Let's assume it's created at `src/styles/variables.scss`.
209
+
Now we're in need of a SCSS file to hold some variables. Let's assume it's created at `src/styles/variables.scss`.
210
210
211
211
```scss
212
212
// src/styles/variables.scss
213
213
$primary-color: red;
214
214
```
215
215
216
-
As in any `scss` project, we could just `@use './path/to/variables.scss`, but that can also become boring. `svelte-preprocess`[accepts a `prependData`](/docs/preprocessing.md#preprocessors) for almost every processor. Let's use it to prepend our import!
216
+
As in any SCSS project, we could just `@use './path/to/variables.scss`, but that can also become boring. `svelte-preprocess`[accepts a `prependData`](/docs/preprocessing.md#preprocessors) for almost every processor. Let's use it to prepend our import!
0 commit comments