Skip to content

Commit fc80832

Browse files
Merge branch 'master' into optimize-locals
2 parents ace213e + e73061d commit fc80832

14 files changed

+1188
-917
lines changed

README.md

+55
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ module.exports = {
407407
- **[`publicPath`](#publicPath)**
408408
- **[`emit`](#emit)**
409409
- **[`esModule`](#esModule)**
410+
- **[`defaultExport`](#defaultExport)**
410411

411412
#### `publicPath`
412413

@@ -549,6 +550,60 @@ module.exports = {
549550
};
550551
```
551552

553+
#### `defaultExport`
554+
555+
Type:
556+
557+
```ts
558+
type defaultExport = boolean;
559+
```
560+
561+
Default: `false`
562+
563+
> **Note**
564+
>
565+
> This option will work only when you set `namedExport` to `true` in `css-loader`
566+
567+
By default, `mini-css-extract-plugin` generates JS modules based on the `esModule` and `namedExport` options in `css-loader`.
568+
Using the `esModule` and `namedExport` options will allow you to better optimize your code.
569+
If you set `esModule: true` and `namedExport: true` for `css-loader` `mini-css-extract-plugin` will generate **only** a named export.
570+
Our official recommendation is to use only named export for better future compatibility.
571+
But for some applications, it is not easy to quickly rewrite the code from the default export to a named export.
572+
573+
In case you need both default and named exports, you can enable this option:
574+
575+
**webpack.config.js**
576+
577+
```js
578+
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
579+
580+
module.exports = {
581+
plugins: [new MiniCssExtractPlugin()],
582+
module: {
583+
rules: [
584+
{
585+
test: /\.css$/i,
586+
use: [
587+
{
588+
loader: MiniCssExtractPlugin.loader,
589+
options: {
590+
defaultExport: true,
591+
},
592+
},
593+
{
594+
loader: "css-loader",
595+
esModule: true,
596+
modules: {
597+
namedExport: true,
598+
},
599+
},
600+
],
601+
},
602+
],
603+
},
604+
};
605+
```
606+
552607
## Examples
553608

554609
### Recommended

0 commit comments

Comments
 (0)