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. Nonetheless, it's useful to understand how to use the compiler, since bundler plugins generally expose compiler options to you.
### `compile`
### `svelte.compile`
```js ```js
result: { result: {
@ -21,17 +22,17 @@ result: {
warnings, warnings,
vars, vars,
stats 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 ```js
const {compile} = require('svelte/compiler'); const svelte = require('svelte/compiler');
const result = compile(source, { const result = svelte.compile(source, {
// options // options
}); });
``` ```
@ -91,7 +92,7 @@ const {
warnings, warnings,
vars, vars,
stats stats
} = compile(source); } = svelte.compile(source);
``` ```
* `js` and `css` are objects with the following properties: * `js` and `css` are objects with the following properties:
@ -146,19 +147,19 @@ compiled: {
stats: { stats: {
timings: { [label]: number } timings: { [label]: number }
} }
} = compile(source: string, options?: {...}) } = svelte.compile(source: string, options?: {...})
``` ```
--> -->
### `preprocess` ### `svelte.preprocess`
```js ```js
result: { result: {
code: string, code: string,
dependencies: Array<string> dependencies: Array<string>
} = preprocess( } = svelte.preprocess(
source: string, source: string,
preprocessors: Array<{ preprocessors: Array<{
markup?: (input: { source: string, filename: string }) => Promise<{ 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. > 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 ```js
const {preprocess} = require('svelte/compiler'); const svelte = require('svelte/compiler');
const { code } = preprocess(source, { const { code } = svelte.preprocess(source, {
markup: ({ content, filename }) => { markup: ({ content, filename }) => {
return { return {
code: content.replace(/foo/g, 'bar') 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). 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 ```js
const {preprocess} = require('svelte/compiler'); const svelte = require('svelte/compiler');
const sass = require('node-sass'); const sass = require('node-sass');
const { dirname } = require('path'); const { dirname } = require('path');
const { code, dependencies } = preprocess(source, { const { code, dependencies } = svelte.preprocess(source, {
style: async ({ content, attributes, filename }) => { style: async ({ content, attributes, filename }) => {
// only process <style lang="sass"> // only process <style lang="sass">
if (attributes.lang !== 'sass') return; 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`. 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 ```js
const {preprocess} = require('svelte/compiler'); const svelte = require('svelte/compiler');
const { code } = preprocess(source, [ const { code } = svelte.preprocess(source, [
{ {
markup: () => { markup: () => {
console.log('this runs first'); console.log('this runs first');
@ -279,13 +280,13 @@ const { code } = preprocess(source, [
``` ```
### `VERSION` ### `svelte.VERSION`
--- ---
The current version, as set in package.json. The current version, as set in package.json.
```js ```js
const {VERSION} = require('svelte/compiler'); const svelte = require('svelte/compiler');
console.log(`running svelte version ${VERSION}`); console.log(`running svelte version ${svelte.VERSION}`);
``` ```

Loading…
Cancel
Save