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
Note that the configuration shown above switches off `MiniCssExtractPlugin` in development mode in favour of using CSS javascript injection. This is recommended by `MiniCssExtractPlugin` because it does not support hot reloading.
108
-
109
-
`prod` indicates, that `NODE_ENV=production` has been set from `package.json` or manually (`NODE_ENV=production npx webpack`) for production builds. We can rely on that to make dynamic adjustments to the config.
110
-
111
103
Additionally, if you're using multiple entrypoints, you may wish to change `new MiniCssExtractPlugin('styles.css')` for `new MiniCssExtractPlugin('[name].css')` to generate one CSS file per entrypoint.
112
104
113
105
Warning: in production, if you have set `sideEffects: false` in your `package.json`, `MiniCssExtractPlugin` has a tendency to drop CSS, regardless of whether it's included in your svelte components.
@@ -144,7 +136,7 @@ module.exports = {
144
136
{
145
137
test:/\.css$/,
146
138
use: [
147
-
prod ?MiniCssExtractPlugin.loader:'style-loader',
139
+
MiniCssExtractPlugin.loader,
148
140
{
149
141
loader:'css-loader',
150
142
options: {
@@ -203,7 +195,6 @@ module.exports = {
203
195
...
204
196
{
205
197
test:/\.(html|svelte)$/,
206
-
exclude:/node_modules/,
207
198
use: {
208
199
loader:'svelte-loader',
209
200
options: {
@@ -276,6 +267,88 @@ module.exports = {
276
267
}
277
268
```
278
269
270
+
### CSS @import in components
271
+
272
+
It is advised to inline any css `@import` in component's style tag before it hits `css-loader`.
273
+
274
+
This ensures equal css behavior when using HMR with `emitCss: false` and production.
If you are using autoprefixer for `.css`, then it is better to exclude emitted css, because it was already processed with `postcss` through `svelte-preprocess` before emitting.
321
+
322
+
```javascript
323
+
...
324
+
module: {
325
+
rules: [
326
+
...
327
+
{
328
+
test:/\.css$/,
329
+
exclude:/svelte\.\d+\.css/,
330
+
use: [
331
+
MiniCssExtractPlugin.loader,
332
+
'css-loader',
333
+
'postcss-loader'
334
+
]
335
+
},
336
+
{
337
+
test:/\.css$/,
338
+
include:/svelte\.\d+\.css/,
339
+
use: [
340
+
MiniCssExtractPlugin.loader,
341
+
'css-loader'
342
+
]
343
+
},
344
+
...
345
+
]
346
+
},
347
+
...
348
+
```
349
+
350
+
This ensures that global css is being processed with `postcss` through webpack rules, and svelte component's css is being processed with `postcss` through `svelte-preprocess`.
0 commit comments