mirror of
https://github.com/sveltejs/svelte.git
synced 2024-12-01 17:30:59 +01:00
flesh out svelte/register docs
This commit is contained in:
parent
df602b74b0
commit
8f2ccc407e
@ -556,20 +556,33 @@ 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`
|
||||
|
||||
To render Svelte components server-side, use `require('svelte/register')`; after this, you can use `require` to include any `.svelte` file.
|
||||
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');
|
||||
const App = require('./App.svelte').default;
|
||||
|
||||
...
|
||||
|
||||
App.default.render({ title: 'name' });
|
||||
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
|
||||
|
||||
#### Creating a component
|
||||
|
Loading…
Reference in New Issue
Block a user