Skip to content

Commit f9bff07

Browse files
authored
Fix hotOptions documentation in readme (#162)
1 parent 5dcecb0 commit f9bff07

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

README.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ If your Svelte components contain `<style>` tags, by default the compiler will a
6464
A better option is to extract the CSS into a separate file. Using the `emitCss` option as shown below would cause a virtual CSS file to be emitted for each Svelte component. The resulting file is then imported by the component, thus following the standard Webpack compilation flow. Add [MiniCssExtractPlugin](https://github.com/webpack-contrib/mini-css-extract-plugin) to the mix to output the css to a separate file.
6565

6666
```javascript
67-
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
68-
const mode = process.env.NODE_ENV || 'development';
69-
const prod = mode === 'production';
67+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
68+
const mode = process.env.NODE_ENV || 'development';
69+
const prod = mode === 'production';
7070
...
7171
module: {
7272
rules: [
@@ -191,6 +191,11 @@ This loader supports component-level HMR via the community supported [svelte-hmr
191191
Configure inside your `webpack.config.js`:
192192

193193
```javascript
194+
// It is recommended to adjust svelte options dynamically, by using
195+
// environment variables
196+
const mode = process.env.NODE_ENV || 'development';
197+
const prod = mode === 'production';
198+
194199
module.exports = {
195200
...
196201
module: {
@@ -204,20 +209,19 @@ module.exports = {
204209
options: {
205210
compilerOptions: {
206211
// NOTE Svelte's dev mode MUST be enabled for HMR to work
207-
// -- in a real config, you'd probably set it to false for prod build,
208-
// based on a env variable or so
209-
dev: true,
212+
dev: !prod, // Default: false
210213
},
211214

212215
// NOTE emitCss: true is currently not supported with HMR
213216
// Enable it for production to output separate css file
214-
emitCss: false,
217+
emitCss: prod, // Default: false
215218
// Enable HMR only for dev mode
216-
hotReload: true, // Default: false
217-
// Extra HMR options
219+
hotReload: !prod, // Default: false
220+
// Extra HMR options, the defaults are completely fine
221+
// You can safely omit hotOptions altogether
218222
hotOptions: {
219223
// Prevent preserving local component state
220-
noPreserveState: false,
224+
preserveLocalState: false,
221225

222226
// If this string appears anywhere in your component's code, then local
223227
// state won't be preserved, even when noPreserveState is false

0 commit comments

Comments
 (0)