Skip to content

Commit 102220b

Browse files
committed
docs: ✏️ Add babel to readme
1 parent 2b20b15 commit 102220b

File tree

5 files changed

+387
-19
lines changed

5 files changed

+387
-19
lines changed

README.md

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77

88
- [Installation](#installation)
99
- [Features](#features)
10-
- [Template tag support](#template-tag-support)
11-
- [External files support](#external-files-support)
12-
- [Global style support](#global-style-support)
13-
- [Preprocessors support](#preprocessors-support)
10+
- [Template tag](#template-tag)
11+
- [External files](#external-files)
12+
- [Global style](#global-style)
13+
- [Preprocessors](#preprocessors)
14+
- [Modern Javascript syntax](#modern-javascript-syntax)
1415
- [Usage](#usage)
1516
- [With `rollup-plugin-svelte`](#with-rollup-plugin-svelte)
1617
- [With `svelte-loader`](#with-svelte-loader)
@@ -35,9 +36,10 @@
3536

3637
The preprocessor module installation is up to the developer.
3738

38-
- `postcss`: `npm install -D postcss postcss-load-config`
39+
- `babel`: `npm install -D @babel/core @babel/preset-...`
3940
- `coffeescript`: `npm install -D coffeescript`
4041
- `typescript`: `npm install -D typescript`
42+
- `postcss`: `npm install -D postcss postcss-load-config`
4143
- `less`: `npm install -D less`
4244
- `sass`: `npm install -D node-sass` or `npm install -D sass`
4345
- `pug`: `npm install -D pug`
@@ -47,7 +49,7 @@ _Note: If you want to load your `postcss` configuration from a external file, ma
4749

4850
## Features
4951

50-
### Template tag support
52+
### Template tag
5153

5254
Add _vue-like_ support for defining your markup between a `<template>` tag. The tagname can be customized to something like `markup` for example. See [#options](#options).
5355

@@ -63,15 +65,15 @@ _Note: only for auto preprocessing_
6365
<script></script>
6466
```
6567

66-
### External files support
68+
### External files
6769

6870
```html
6971
<template src="./template.html"></template>
7072
<script src="./script.js"></script>
7173
<style src="./style.css"></style>
7274
```
7375

74-
### Global style support
76+
### Global style
7577

7678
Add a `global` attribute to your `style` tag and instead of scoping the css, all of its content will be interpreted as global style.
7779

@@ -86,9 +88,9 @@ Add a `global` attribute to your `style` tag and instead of scoping the css, all
8688
_Note<sup>1</sup>: needs postcss to be installed_
8789
_Note<sup>2</sup>: if you're using it as a standalone processor, it works best if added to the end of the processors array._
8890

89-
### Preprocessors support
91+
### Preprocessors
9092

91-
Current supported out-of-the-box preprocessors are `SCSS`, `Stylus`, `Less`, `Coffeescript`, `TypeScript`, `Pug` and `PostCSS`.
93+
Current supported out-of-the-box preprocessors are `SCSS`, `Stylus`, `Less`, `Coffeescript`, `TypeScript`, `Pug`, `PostCSS`, `Babel`.
9294

9395
```html
9496
<template lang="pug">
@@ -132,6 +134,38 @@ Current supported out-of-the-box preprocessors are `SCSS`, `Stylus`, `Less`, `Co
132134
</style>
133135
```
134136
137+
### Modern Javascript syntax
138+
139+
`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+.
140+
141+
For example, with `@babel/preset-env` your config could be:
142+
143+
```js
144+
import preprocess from 'svelte-preprocess'
145+
...
146+
preprocess: preprocess({
147+
babel: {
148+
presets: [
149+
[
150+
'@babel/preset-env',
151+
{
152+
loose: true,
153+
// No need for babel to resolve modules
154+
modules: false,
155+
targets: {
156+
// ! Very important. Target es6+
157+
esmodules: true,
158+
},
159+
},
160+
],
161+
],
162+
},
163+
});
164+
...
165+
```
166+
167+
_Note: If you want to transpile your app to be supported in older browsers, you must run babel from the context of your bundler._
168+
135169
## Usage
136170
137171
### With `rollup-plugin-svelte`

package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@
4848
"^.+\\.tsx?$": "ts-jest"
4949
}
5050
},
51+
"husky": {
52+
"hooks": {
53+
"'pre-commit'": "lint-staged"
54+
}
55+
},
56+
"lint-staged": {
57+
"*.{ts,js,tsx,jsx}": ["eslint --fix", "prettier --write"],
58+
"*.json": ["prettier --write"]
59+
},
5160
"devDependencies": {
5261
"@babel/core": "^7.8.4",
5362
"@babel/preset-env": "^7.8.4",
@@ -60,8 +69,10 @@
6069
"conventional-changelog-cli": "^2.0.31",
6170
"eslint": "^6.8.0",
6271
"eslint-config-kaisermann": "0.1.0",
72+
"husky": "^4.2.3",
6373
"jest": "^25.1.0",
6474
"less": "^3.10.3",
75+
"lint-staged": "^10.0.8",
6576
"node-sass": "^4.13.1",
6677
"postcss": "^7.0.26",
6778
"postcss-easy-import": "^3.0.0",

src/autoProcess.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
TransformerOptions,
1515
Preprocessor,
1616
Options,
17-
Processed,
1817
ProcessedScript,
1918
} from './types';
2019

test/processors.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ describe(`processor - babel`, () => {
8585
],
8686
}),
8787
]);
88-
console.log(preprocessed);
8988
expect(preprocessed.toString()).toMatchInlineSnapshot(`
9089
"<script src=\\"./fixtures/script.babel.js\\">export var hello = {};
9190
export var world = hello == null ? void 0 : hello.value;</script><div></div>"

0 commit comments

Comments
 (0)