Skip to content

Commit 10cc49b

Browse files
committed
update docs
1 parent 9583f06 commit 10cc49b

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

README.md

+78
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,84 @@ module.exports = {
113113

114114
This should create an additional `styles.css.map` file.
115115

116+
### Hot Reload
117+
118+
Hot reloading is turned off by default, you can turn it on using the `hotReload` option as shown below:
119+
120+
```javascript
121+
...
122+
module: {
123+
rules: [
124+
...
125+
{
126+
test: /\.(html|svelte)$/,
127+
exclude: /node_modules/,
128+
use: 'svelte-loader',
129+
options: {
130+
hotReload: true
131+
}
132+
}
133+
...
134+
]
135+
}
136+
...
137+
```
138+
139+
#### Hot reload rules and caveats:
140+
141+
- `_rerender` and `_register` are reserved method names, please don't use them in `methods:{...}`
142+
- Turning `dev` mode on (`dev:true`) is **not** necessary.
143+
- Modifying the HTML (template) part of your component will replace and re-render the changes in place. Current local state of the component will also be preserved (this can be turned off per component see [Stop preserving state](#stop-preserving-state)).
144+
- When modifying the `<script>` part of your component, instances will be replaced and re-rendered in place too.
145+
However if your component has lifecycle methods that produce global side-effects, you might need to reload the whole page.
146+
- If you are using `svelte/store`, a full reload is required if you modify `store` properties
147+
148+
149+
Components will **not** be hot reloaded in the following situations:
150+
1. `process.env.NODE_ENV === 'production'`
151+
2. Webpack is minifying code
152+
3. Webpack's `target` is `node` (i.e SSR components)
153+
4. `generate` option has a value of `ssr`
154+
155+
#### Stop preserving state
156+
157+
Sometimes it might be necessary for some components to avoid state preservation on hot reload.
158+
159+
This can be configured on a per-component basis by adding a property `noPreserveState = true` to the component's constructor using the `setup()` method. For example:
160+
```js
161+
export default {
162+
setup(comp){
163+
comp.noPreserveState = true;
164+
},
165+
data(){return {...}},
166+
oncreate(){...}
167+
}
168+
```
169+
170+
Or, on a global basis by adding `{noPreserveState: true}` to `hotOptions`. For example:
171+
```js
172+
{
173+
test: /\.(html|svelte)$/,
174+
exclude: /node_modules/,
175+
use: [
176+
{
177+
loader: 'svelte-loader',
178+
options: {
179+
hotReload: true,
180+
hotOptions: {
181+
noPreserveState: true
182+
}
183+
}
184+
}
185+
]
186+
}
187+
```
188+
189+
**Please Note:** If you are using `svelte/store`, `noPreserveState` has no effect on `store` properties. Neither locally, nor globally.
190+
191+
192+
193+
116194
## License
117195

118196
MIT

0 commit comments

Comments
 (0)