Skip to content

Commit 712cb28

Browse files
[feat] vitePreprocess (#8036)
* [feat] vitePreprocess * fix test Co-authored-by: Rich Harris <[email protected]>
1 parent eddedc8 commit 712cb28

File tree

12 files changed

+31
-76
lines changed

12 files changed

+31
-76
lines changed

.changeset/sour-bears-raise.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'create-svelte': patch
3+
'@sveltejs/kit': patch
4+
---
5+
6+
[feat] vitePreprocess

documentation/docs/60-appendix/05-integrations.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,25 @@ title: Integrations
44

55
## Preprocessors
66

7-
Preprocessors transform your `.svelte` files before passing them to the compiler. For example, if your `.svelte` file uses TypeScript and PostCSS, it must first be transformed into JavaScript and CSS so that the Svelte compiler can handle it. There are many [available preprocessors](https://sveltesociety.dev/tools#preprocessors).
7+
Preprocessors transform your `.svelte` files before passing them to the compiler. For example, if your `.svelte` file uses TypeScript and PostCSS, it must first be transformed into JavaScript and CSS so that the Svelte compiler can handle it. There are many [available preprocessors](https://sveltesociety.dev/tools#preprocessors). The Svelte team maintains two official ones discussed below.
88

9-
[`svelte-preprocess`](https://github.com/sveltejs/svelte-preprocess) automatically transforms the code in your Svelte templates to provide support for TypeScript, PostCSS, scss/sass, Less, and many other technologies (except CoffeeScript which is [not supported](https://github.com/sveltejs/kit/issues/2920#issuecomment-996469815) by SvelteKit). The first step of setting it up is to add `svelte-preprocess` to your [`svelte.config.js`](/docs/configuration). It is provided by the template if you're using TypeScript whereas JavaScript users will need to add it. After that, you will often only need to install the corresponding library such as `npm install -D sass` or `npm install -D less`. See the [`svelte-preprocess`](https://github.com/sveltejs/svelte-preprocess) docs for more details.
9+
### `vitePreprocess`
1010

11-
`vite-plugin-svelte` also offers a [`vitePreprocess`](https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/preprocess.md) feature which will utilize Vite for preprocessing which may be faster and require less configuration. To use this option, first run `npm install --save-dev @sveltejs/vite-plugin-svelte` and then update your `svelte.config.js`:
11+
`vite-plugin-svelte` offers a [`vitePreprocess`](https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/preprocess.md) feature which utilizes Vite for preprocessing. It is capable of handling the language flavors Vite handles: TypeScript, PostCSS, SCSS, Less, Stylus, and SugarSS. For convenience, it is re-exported from the `@sveltejs/kit/vite` package. If you set your project up with TypeScript it will be included by default:
1212

1313
```js
1414
// svelte.config.js
15-
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
15+
import { vitePreprocess } from '@sveltejs/kit/vite';
1616

1717
export default {
1818
preprocess: [vitePreprocess()]
1919
};
2020
```
2121

22+
### `svelte-preprocess`
23+
24+
[`svelte-preprocess`](https://github.com/sveltejs/svelte-preprocess) automatically transforms the code in your Svelte templates to provide support for TypeScript, PostCSS, scss/sass, Less, and many other technologies (except CoffeeScript which is [not supported](https://github.com/sveltejs/kit/issues/2920#issuecomment-996469815) by SvelteKit). `vitePreprocess` may be faster and require less configuration, so it is used by default. However, `svelte-preprocess` has some additional functionality not found in `vitePreprocess`. The first step of setting it up is to add `svelte-preprocess` to your [`svelte.config.js`](/docs/configuration). After that, you will often only need to install the corresponding library such as `npm install -D sass` or `npm install -D less`. See the [`svelte-preprocess`](https://github.com/sveltejs/svelte-preprocess) docs for more details.
25+
2226
## Adders
2327

2428
[Svelte Adders](https://sveltesociety.dev/templates#adders) allow you to setup many different complex integrations like Tailwind, PostCSS, Storybook, Firebase, GraphQL, mdsvex, and more with a single command. Please see [sveltesociety.dev](https://sveltesociety.dev/) for a full listing of templates, components, and tools available for use with Svelte and SvelteKit.

packages/create-svelte/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"prettier-plugin-svelte": "^2.8.1",
2626
"sucrase": "^3.29.0",
2727
"svelte": "^3.54.0",
28-
"svelte-preprocess": "^4.10.7",
2928
"tiny-glob": "^0.2.9",
3029
"uvu": "^0.5.6"
3130
},

packages/create-svelte/shared/+default+checkjs/svelte.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import adapter from '@sveltejs/adapter-auto';
2-
import preprocess from 'svelte-preprocess';
2+
import { vitePreprocess } from '@sveltejs/kit/vite';
33

44
/** @type {import('@sveltejs/kit').Config} */
55
const config = {
6-
// Consult https://github.com/sveltejs/svelte-preprocess
6+
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
77
// for more information about preprocessors
8-
preprocess: preprocess(),
8+
preprocess: vitePreprocess(),
99

1010
kit: {
1111
adapter: adapter()

packages/create-svelte/shared/+default+typescript/svelte.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import adapter from '@sveltejs/adapter-auto';
2-
import preprocess from 'svelte-preprocess';
2+
import { vitePreprocess } from '@sveltejs/kit/vite';
33

44
/** @type {import('@sveltejs/kit').Config} */
55
const config = {
6-
// Consult https://github.com/sveltejs/svelte-preprocess
6+
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
77
// for more information about preprocessors
8-
preprocess: preprocess(),
8+
preprocess: vitePreprocess(),
99

1010
kit: {
1111
adapter: adapter()

packages/create-svelte/shared/+typescript/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"devDependencies": {
77
"typescript": "^4.9.3",
88
"tslib": "^2.4.1",
9-
"svelte-check": "^2.9.2",
10-
"svelte-preprocess": "^4.10.7"
9+
"svelte-check": "^2.9.2"
1110
}
1211
}

packages/create-svelte/shared/+typescript/svelte.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import adapter from '@sveltejs/adapter-auto';
2-
import preprocess from 'svelte-preprocess';
2+
import { vitePreprocess } from '@sveltejs/kit/vite';
33

44
/** @type {import('@sveltejs/kit').Config} */
55
const config = {
6-
// Consult https://github.com/sveltejs/svelte-preprocess
6+
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
77
// for more information about preprocessors
8-
preprocess: preprocess(),
8+
preprocess: vitePreprocess(),
99

1010
kit: {
1111
adapter: adapter()

packages/create-svelte/templates/default/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"@sveltejs/adapter-auto": "workspace:*",
1313
"@sveltejs/kit": "workspace:*",
1414
"svelte": "^3.54.0",
15-
"svelte-preprocess": "^4.10.7",
1615
"typescript": "^4.9.3",
1716
"vite": "^4.0.0"
1817
},

packages/create-svelte/templates/default/svelte.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import adapter from '@sveltejs/adapter-auto';
2-
import preprocess from 'svelte-preprocess';
2+
import { vitePreprocess } from '@sveltejs/kit/vite';
33

44
// This config is ignored and replaced with one of the configs in the shared folder when a project is created.
55

66
/** @type {import('@sveltejs/kit').Config} */
77
const config = {
8-
// Consult https://github.com/sveltejs/svelte-preprocess
8+
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
99
// for more information about preprocessors
10-
preprocess: preprocess(),
10+
preprocess: vitePreprocess(),
1111

1212
kit: {
1313
adapter: adapter()

packages/kit/src/exports/vite/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import { create_static_module, create_dynamic_module } from '../../core/env.js';
2020
import { is_illegal, module_guard, normalize_id } from './graph_analysis/index.js';
2121
import { create_assets } from '../../core/sync/create_manifest_data/index.js';
2222

23+
export { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
24+
2325
const cwd = process.cwd();
2426

2527
/** @type {import('./types').EnforcedConfig} */

0 commit comments

Comments
 (0)