Skip to content

Commit 9c23056

Browse files
committed
Adjust configs to match real world scenario
1 parent d51187f commit 9c23056

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

README.md

Lines changed: 11 additions & 8 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,16 +209,14 @@ 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
219+
hotReload: !prod, // Default: false
217220
// Extra HMR options, the defaults are completely fine
218221
// You can safely omit hotOptions altogether
219222
hotOptions: {

0 commit comments

Comments
 (0)