Skip to content

Commit be6893f

Browse files
committed
Adjust configs to match real world scenario
1 parent a6e4d36 commit be6893f

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: [
@@ -174,6 +174,11 @@ This loader supports component-level HMR via the community supported [svelte-hmr
174174
Configure inside your `webpack.config.js`:
175175

176176
```javascript
177+
// It is recommended to adjust svelte options dynamically, by using
178+
// environment variables
179+
const mode = process.env.NODE_ENV || 'development';
180+
const prod = mode === 'production';
181+
177182
module.exports = {
178183
...
179184
module: {
@@ -187,16 +192,14 @@ module.exports = {
187192
options: {
188193
compilerOptions: {
189194
// NOTE Svelte's dev mode MUST be enabled for HMR to work
190-
// -- in a real config, you'd probably set it to false for prod build,
191-
// based on a env variable or so
192-
dev: true,
195+
dev: !prod, // Default: false
193196
},
194197

195198
// NOTE emitCss: true is currently not supported with HMR
196199
// Enable it for production to output separate css file
197-
emitCss: false,
200+
emitCss: prod, // Default: false
198201
// Enable HMR only for dev mode
199-
hotReload: true, // Default: false
202+
hotReload: !prod, // Default: false
200203
// Extra HMR options, the defaults are completely fine
201204
// You can safely omit hotOptions altogether
202205
hotOptions: {

0 commit comments

Comments
 (0)