Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 42 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ module.exports = {
plugins: [
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// all options are optional
// both options are optional
filename: '[name].css',
chunkFilename: '[id].css',
ignoreOrder: false, // Enable to remove warnings about conflicting order
}),
],
module: {
Expand Down Expand Up @@ -203,6 +202,46 @@ module.exports = {
};
```

#### `esModules`

Type: `boolean`
Default: `false`

By default, extract-mini-css-plugin generates JS modules that use the CommonJS syntax. However, there are some
cases in which using ES2015 modules is more beneficial, like in the case of [module concatenation](https://webpack.js.org/plugins/module-concatenation-plugin/) and [tree shaking](https://webpack.js.org/guides/tree-shaking/).

**webpack.config.js**

```js
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
module.exports = {
plugins: [
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: '[name].css',
chunkFilename: '[id].css',
}),
],
module: {
rules: [
{
test: /\.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
esModules: true,
},
},
'css-loader',
],
},
],
},
};
```

### Minimizing For Production

To minify the output, use a plugin like [optimize-css-assets-webpack-plugin](https://github.com/NMFR/optimize-css-assets-webpack-plugin). Setting `optimization.minimizer` overrides the defaults provided by webpack, so make sure to also specify a JS minimizer:
Expand Down Expand Up @@ -359,13 +398,7 @@ For long term caching use `filename: "[contenthash].css"`. Optionally add `[name

### Remove Order Warnings

For projects where css ordering has been mitigated through consistent use of scoping or naming conventions, the css order warnings can be disabled by setting the ignoreOrder flag to true for the plugin.

```javascript
new MiniCssExtractPlugin({
ignoreOrder: true,
}),
```
If the terminal is getting bloated with chunk order warnings. You can filter by configuring [warningsFilter](https://webpack.js.org/configuration/stats/) withing the webpack stats option

### Media Query Plugin

Expand Down
7 changes: 6 additions & 1 deletion src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,14 @@ export function pitch(request) {
return callback(e);
}

const esModules =
typeof options.esModules === 'boolean' && options.esModules === true;

let resultSource = `// extracted by ${pluginName}`;
const result = locals
? `\nmodule.exports = ${JSON.stringify(locals)};`
? `\n${
esModules ? 'export default ' : 'module.exports = '
}${JSON.stringify(locals)};`
: '';

resultSource += options.hmr
Expand Down