diff --git a/README.md b/README.md
index 6b03ad79..f4ada96d 100644
--- a/README.md
+++ b/README.md
@@ -117,6 +117,7 @@ module.exports = {
|[`config`](#config)|`{Object}`|`undefined`|Set `postcss.config.js` config path && `ctx`|
|[`plugins`](#plugins)|`{Array\|Function}`|`[]`|Set PostCSS Plugins|
|[`sourceMap`](#sourcemap)|`{String\|Boolean}`|`false`|Enable Source Maps|
+|[`emitWarningsAsErrors`](#emitwarningsaserrors)|`{Boolean}`|`false`|Emit warnings as errors|
### `Exec`
@@ -305,6 +306,22 @@ within the CSS directly as an annotation comment.
/*# sourceMappingURL=data:application/json;base64, ... */
```
+### `EmitWarningsAsErrors`
+
+Enabling `emitWarningsAsErrors` will emit any warnings from postcss plugins at the error level.
+
+**`webpack.config.js`**
+```js
+{
+ test: /\.css$/,
+ use: [
+ ...,
+ { loader: 'postcss-loader', options: { emitWarningsAsErrors: true } }
+ ]
+}
+```
+
+
Examples
### `Stylelint`
diff --git a/src/index.js b/src/index.js
index bb576c32..30e09f12 100644
--- a/src/index.js
+++ b/src/index.js
@@ -31,6 +31,7 @@ function loader (css, map, meta) {
const file = this.resourcePath
const sourceMap = options.sourceMap
+ const emitWarningsAsErrors = options.emitWarningsAsErrors
Promise.resolve().then(() => {
const length = Object.keys(options)
@@ -40,6 +41,7 @@ function loader (css, map, meta) {
case 'ident':
case 'config':
case 'sourceMap':
+ case 'emitWarningsAsErrors':
return
default:
return option
@@ -142,8 +144,9 @@ function loader (css, map, meta) {
.then((result) => {
let { css, map, root, processor, messages } = result
- result.warnings().forEach((warning) => {
- this.emitWarning(new Warning(warning))
+ result.warnings().forEach(warning => {
+ const emit = emitWarningsAsErrors ? this.emitError : this.emitWarning
+ emit(new Warning(warning))
})
messages.forEach((msg) => {
diff --git a/src/options.json b/src/options.json
index 1141d84a..668a5a95 100644
--- a/src/options.json
+++ b/src/options.json
@@ -40,6 +40,9 @@
},
"sourceMap": {
"type": [ "string", "boolean" ]
+ },
+ "emitWarningsAsErrors": {
+ "type": ["boolean"]
}
},
"errorMessage": {
@@ -50,7 +53,8 @@
"syntax": "should be {String|Object} (https://github.com/postcss/postcss-loader#syntax)",
"stringifier": "should be {String|Object} (https://github.com/postcss/postcss-loader#stringifier)",
"plugins": "should be {Array|Object|Function} (https://github.com/postcss/postcss-loader#plugins)",
- "sourceMap": "should be {String|Boolean} (https://github.com/postcss/postcss-loader#sourcemap)"
+ "sourceMap": "should be {String|Boolean} (https://github.com/postcss/postcss-loader#sourcemap)",
+ "emitWarningsAsErrors": "should be {Boolean} (https://github.com/postcss/postcss-loader#emitWarningsAsError)"
}
},
"additionalProperties": true
diff --git a/test/Warnings.test.js b/test/Warnings.test.js
index 7c5875b7..e7f3cbb4 100644
--- a/test/Warnings.test.js
+++ b/test/Warnings.test.js
@@ -30,4 +30,29 @@ describe('Warnings', () => {
expect(message).toMatchSnapshot()
})
})
+
+ test('Emit as Error', () => {
+ const config = {
+ loader: {
+ test: /\.css$/,
+ options: {
+ emitWarningsAsErrors: true,
+ plugins: [
+ plugin()
+ ]
+ }
+ }
+ }
+
+ return webpack('css/index.js', config).then((stats) => {
+ const error = stats.compilation.errors[0]
+
+ const message = error.message
+ .split('\n')
+ .slice(1)
+ .join('\n')
+
+ expect(message).toMatchSnapshot()
+ })
+ })
})
diff --git a/test/__snapshots__/Warnings.test.js.snap b/test/__snapshots__/Warnings.test.js.snap
index 9524418a..407d63c9 100644
--- a/test/__snapshots__/Warnings.test.js.snap
+++ b/test/__snapshots__/Warnings.test.js.snap
@@ -1,5 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
+exports[`Warnings Emit as Error 1`] = `
+"Warning
+
+(1:5) "
+`;
+
exports[`Warnings Plugins 1`] = `
"Warning