You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+78
Original file line number
Diff line number
Diff line change
@@ -113,6 +113,84 @@ module.exports = {
113
113
114
114
This should create an additional `styles.css.map` file.
115
115
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
+
exportdefault {
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.
0 commit comments