keep svelte prefix for compiler exports

pull/2385/head
Rich Harris 6 years ago
parent 795d9b7e66
commit 8e78448a39

@ -11,7 +11,8 @@ Typically, you won't interact with the Svelte compiler directly, but will instea
Nonetheless, it's useful to understand how to use the compiler, since bundler plugins generally expose compiler options to you.
### `compile`
### `svelte.compile`
```js
result: {
@ -21,17 +22,17 @@ result: {
warnings,
vars,
stats
} = compile(source: string, options?: {...})
} = svelte.compile(source: string, options?: {...})
```
---
This is where the magic happens. `compile` takes your component source code, and turns it into a JavaScript module that exports a class.
This is where the magic happens. `svelte.compile` takes your component source code, and turns it into a JavaScript module that exports a class.
```js
const {compile} = require('svelte/compiler');
const svelte = require('svelte/compiler');
const result = compile(source, {
const result = svelte.compile(source, {
// options
});
```
@ -91,7 +92,7 @@ const {
warnings,
vars,
stats
} = compile(source);
} = svelte.compile(source);
```
* `js` and `css` are objects with the following properties:
@ -146,19 +147,19 @@ compiled: {
stats: {
timings: { [label]: number }
}
} = compile(source: string, options?: {...})
} = svelte.compile(source: string, options?: {...})
```
-->
### `preprocess`
### `svelte.preprocess`
```js
result: {
code: string,
dependencies: Array<string>
} = preprocess(
} = svelte.preprocess(
source: string,
preprocessors: Array<{
markup?: (input: { source: string, filename: string }) => Promise<{
@ -193,9 +194,9 @@ The `markup` function receives the entire component source text, along with the
> Preprocessor functions may additionally return a `map` object alongside `code` and `dependencies`, where `map` is a sourcemap representing the transformation. In current versions of Svelte it will be ignored, but future versions of Svelte may take account of preprocessor sourcemaps.
```js
const {preprocess} = require('svelte/compiler');
const svelte = require('svelte/compiler');
const { code } = preprocess(source, {
const { code } = svelte.preprocess(source, {
markup: ({ content, filename }) => {
return {
code: content.replace(/foo/g, 'bar')
@ -213,11 +214,11 @@ The `script` and `style` functions receive the contents of `<script>` and `<styl
If a `dependencies` array is returned, it will be included in the result object. This is used by packages like [rollup-plugin-svelte](https://github.com/rollup/rollup-plugin-svelte) to watch additional files for changes, in the case where your `<style>` tag has an `@import` (for example).
```js
const {preprocess} = require('svelte/compiler');
const svelte = require('svelte/compiler');
const sass = require('node-sass');
const { dirname } = require('path');
const { code, dependencies } = preprocess(source, {
const { code, dependencies } = svelte.preprocess(source, {
style: async ({ content, attributes, filename }) => {
// only process <style lang="sass">
if (attributes.lang !== 'sass') return;
@ -248,9 +249,9 @@ const { code, dependencies } = preprocess(source, {
Multiple preprocessors can be used together. The output of the first becomes the input to the second. `markup` functions run first, then `script` and `style`.
```js
const {preprocess} = require('svelte/compiler');
const svelte = require('svelte/compiler');
const { code } = preprocess(source, [
const { code } = svelte.preprocess(source, [
{
markup: () => {
console.log('this runs first');
@ -279,13 +280,13 @@ const { code } = preprocess(source, [
```
### `VERSION`
### `svelte.VERSION`
---
The current version, as set in package.json.
```js
const {VERSION} = require('svelte/compiler');
console.log(`running svelte version ${VERSION}`);
const svelte = require('svelte/compiler');
console.log(`running svelte version ${svelte.VERSION}`);
```

Loading…
Cancel
Save