Skip to content

Commit

Permalink
Merge pull request #2633 from zlsa/patch-2
Browse files Browse the repository at this point in the history
Add barebones description of `svelte/register`
  • Loading branch information
Rich-Harris authored May 4, 2019
2 parents 203d0ec + 8f2ccc4 commit cfb22e4
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions site/content/docs/03-run-time.md
Original file line number Diff line number Diff line change
Expand Up @@ -556,9 +556,31 @@ You can see a full example on the [animations tutorial](tutorial/animate)

* TODO could have nice little interactive widgets showing the different functions, maybe


### `svelte/register`

TODO
To render Svelte components in Node.js without bundling, use `require('svelte/register')`. After that, you can use `require` to include any `.svelte` file.

```js
require('svelte/register');

const App = require('./App.svelte').default;

...

const { html, css, head } = App.render({ answer: 42 });
```

> The `.default` is necessary because we're converting from native JavaScript modules to the CommonJS modules recognised by Node. Note that if your component imports JavaScript modules, they will fail to load in Node and you will need to use a bundler instead.
To set compile options, or to use a custom file extension, call the `register` hook as a function:

```js
require('svelte/register')({
extensions: ['.customextension'], // defaults to ['.html', '.svelte']
preserveComments: true
});
```


### Client-side component API
Expand All @@ -569,8 +591,6 @@ TODO
const component = new Component(options)
```

---

A client-side component — that is, a component compiled with `generate: 'dom'` (or the `generate` option left unspecified) is a JavaScript class.

```js
Expand Down

0 comments on commit cfb22e4

Please sign in to comment.