cb
-PostCSS Loader
-
-> Loads && processes CSS with [PostCSS](https://github.com/postcss/postcss)
-
-**Kind**: global function
-**Returns**: cb - cb Result
-**Requires**: module:path, module:loader-utils, module:schema-utils, module:postcss, module:postcss-load-config, module:Error
-**Version**: 2.0.0
-**Author**: Andrey Sitnik (@ai) String | Source |
-| map | Object | Source Map |
-
-
-* [loader(css, map)](#loader) β cb
- * [.cb](#loader.cb) : function
- * [.cb](#loader.cb) : function
-
-
-
-### loader.cb : function
-**Kind**: static typedef of [loader](#loader)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| null | Object | Error |
-| result | String | Result (JS Module) |
-| map | Object | Source Map |
-
-
-
-### loader.cb : function
-**Kind**: static typedef of [loader](#loader)
-
-| Param | Type | Description |
-| --- | --- | --- |
-| null | Object | Error |
-| css | String | Result (Raw Module) |
-| map | Object | Source Map |
-
diff --git a/README.md b/README.md
index f7546968..6b03ad79 100644
--- a/README.md
+++ b/README.md
@@ -33,7 +33,7 @@ npm i -D postcss-loader
### `Configuration`
-**postcss.config.js**
+**`postcss.config.js`**
```js
module.exports = {
parser: 'sugarss',
@@ -72,7 +72,7 @@ Config lookup starts from `path.dirname(file)` and walks the file tree upwards u
After setting up your `postcss.config.js`, add `postcss-loader` to your `webpack.config.js`. You can use it standalone or in conjunction with `css-loader` (recommended). Use it **after** `css-loader` and `style-loader`, but **before** other preprocessor loaders like e.g `sass|less|stylus-loader`, if you use any.
-**webpack.config.js**
+**`webpack.config.js`**
```js
module.exports = {
module: {
@@ -88,7 +88,7 @@ module.exports = {
> β οΈ When `postcss-loader` is used standalone (without `css-loader`) don't use `@import` in your CSS, since this can lead to quite bloated bundles
-**webpack.config.js (recommended)**
+**`webpack.config.js` (recommended)**
```js
module.exports = {
module: {
@@ -122,6 +122,7 @@ module.exports = {
If you use JS styles without the [`postcss-js`][postcss-js] parser, add the `exec` option.
+**`webpack.config.js`**
```js
{
test: /\.style.js$/,
@@ -148,7 +149,7 @@ You can manually specify the path to search for your config (`postcss.config.js`
> β οΈ Note that you **can't** use a **filename** other than the [supported config formats] (e.g `.postcssrc.js`, `postcss.config.js`), this option only allows you to manually specify the **directory** where config lookup should **start** from
-**webpack.config.js**
+**`webpack.config.js`**
```js
{
loader: 'postcss-loader',
@@ -173,7 +174,7 @@ You can manually specify the path to search for your config (`postcss.config.js`
`postcss-loader` exposes context `ctx` to the config file, making your `postcss.config.js` dynamic, so can use it to do some real magic β¨
-**postcss.config.js**
+**`postcss.config.js`**
```js
module.exports = ({ file, options, env }) => ({
parser: file.extname === '.sss' ? 'sugarss' : false,
@@ -185,7 +186,7 @@ module.exports = ({ file, options, env }) => ({
})
```
-**webpack.config.js**
+**`webpack.config.js`**
```js
{
loader: 'postcss-loader',
@@ -202,7 +203,7 @@ module.exports = ({ file, options, env }) => ({
### `Plugins`
-**webpack.config.js**
+**`webpack.config.js`**
```js
{
loader: 'postcss-loader',
@@ -229,7 +230,7 @@ module.exports = ({ file, options, env }) => ({
#### `Parser`
-**webpack.config.js**
+**`webpack.config.js`**
```js
{
test: /\.sss$/,
@@ -242,7 +243,7 @@ module.exports = ({ file, options, env }) => ({
#### `Syntax`
-**webpack.config.js**
+**`webpack.config.js`**
```js
{
test: /\.css$/,
@@ -255,7 +256,7 @@ module.exports = ({ file, options, env }) => ({
#### `Stringifier`
-**webpack.config.js**
+**`webpack.config.js`**
```js
{
test: /\.css$/,
@@ -270,7 +271,7 @@ module.exports = ({ file, options, env }) => ({
Enables source map support, `postcss-loader` will use the previous source map given by other loaders and update it accordingly, if no previous loader is applied before `postcss-loader`, the loader will generate a source map for you.
-**webpack.config.js**
+**`webpack.config.js`**
```js
{
test: /\.css/,
@@ -288,7 +289,7 @@ Enables source map support, `postcss-loader` will use the previous source map gi
You can set the `sourceMap: 'inline'` option to inline the source map
within the CSS directly as an annotation comment.
-**webpack.config.js**
+**`webpack.config.js`**
```js
{
loader: 'postcss-loader',
@@ -308,7 +309,7 @@ within the CSS directly as an annotation comment.
### `Stylelint`
-**webpack.config.js**
+**`webpack.config.js`**
```js
{
test: /\.css$/,
@@ -330,9 +331,9 @@ within the CSS directly as an annotation comment.
}
```
-### Autoprefixing
+### `Autoprefixing`
-**webpack.config.js**
+**`webpack.config.js`**
```js
{
test: /\.css$/,
@@ -361,7 +362,7 @@ This loader [cannot be used] with [CSS Modules] out of the box due
to the way `css-loader` processes file imports. To make them work properly,
either add the css-loaderβs [`importLoaders`] option.
-**webpack.config.js**
+**`webpack.config.js`**
```js
{
test: /\.css$/,
@@ -386,6 +387,7 @@ If you want to process styles written in JavaScript, use the [postcss-js] parser
[postcss-js]: https://github.com/postcss/postcss-js
+**`webpack.config.js`**
```js
{
test: /\.style.js$/,
@@ -425,10 +427,11 @@ export default {
[ExtractPlugin]: https://github.com/webpack-contrib/mini-css-extract-plugin
-**webpack.config.js**
+**`webpack.config.js`**
```js
-const MiniCssExtractPlugin = require('mini-css-extract-plugin');
-const devMode = process.env.NODE_ENV !== 'production';
+const devMode = process.env.NODE_ENV !== 'production'
+
+const MiniCssExtractPlugin = require('mini-css-extract-plugin')
module.exports = {
module: {
@@ -438,14 +441,14 @@ module.exports = {
use: [
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
- 'postcss-loader',
+ 'postcss-loader'
]
}
]
},
plugins: [
new MiniCssExtractPlugin({
- filename: devMode ? '[name].css' : '[name].[hash].css',
+ filename: devMode ? '[name].css' : '[name].[hash].css'
})
]
}
diff --git a/docs/LOADER.md b/docs/LOADER.md
new file mode 100644
index 00000000..deb2d04d
--- /dev/null
+++ b/docs/LOADER.md
@@ -0,0 +1,130 @@
+## Modules
+
+ErrorErrorcbPostCSS Loader
+Loads && processes CSS with PostCSS
+PromisePostCSS Options Parser
+Transforms the loader options into a valid postcss config {Object}
module:path, module:loader-utils, module:schema-utils, module:postcss, module:postcss-load-config, module:./options.js, module:./Warning.js, module:./SyntaxError.js
+**Version**: 3.0.0
+**Author**: Andrey Sitnik (@ai) Error
+**Kind**: global class
+**Extends**: Error
+
+
+### new SyntaxError(err)
+**PostCSS Syntax Error**
+
+Loader wrapper for postcss syntax errors
+
+
+| Param | Type | Description |
+| --- | --- | --- |
+| err | Object | CssSyntaxError |
+
+
+
+## Warning β Error
+**Kind**: global class
+**Extends**: Error
+
+
+### new Warning(warning)
+**PostCSS Plugin Warning**
+
+Loader wrapper for postcss plugin warnings (`root.messages`)
+
+
+| Param | Type | Description |
+| --- | --- | --- |
+| warning | Object | PostCSS Warning |
+
+
+
+## loader(css, map) β cb
+**PostCSS Loader**
+
+Loads && processes CSS with [PostCSS](https://github.com/postcss/postcss)
+
+**Kind**: global function
+**Returns**: cb - cb Result
+
+| Param | Type | Description |
+| --- | --- | --- |
+| css | String | Source |
+| map | Object | Source Map |
+
+
+* [loader(css, map)](#loader) β cb
+ * [.cb](#loader.cb) : function
+ * [.cb](#loader.cb) : function
+
+
+
+### loader.cb : function
+**Kind**: static typedef of [loader](#loader)
+
+| Param | Type | Description |
+| --- | --- | --- |
+| null | Object | Error |
+| css | String | Result (JS Module) |
+| map | Object | Source Map |
+
+
+
+### loader.cb : function
+**Kind**: static typedef of [loader](#loader)
+
+| Param | Type | Description |
+| --- | --- | --- |
+| null | Object | Error |
+| css | String | Result (Raw Module) |
+| map | Object | Source Map |
+
+
+
+## parseOptions(exec, parser, syntax, stringifier, plugins) β Promise
+**PostCSS Options Parser**
+
+Transforms the loader options into a valid postcss config `{Object}`
+
+**Kind**: global function
+**Returns**: Promise - PostCSS Config
+
+| Param | Type | Description |
+| --- | --- | --- |
+| exec | Boolean | Execute CSS-in-JS |
+| parser | String \| Object | PostCSS Parser |
+| syntax | String \| Object | PostCSS Syntax |
+| stringifier | String \| Object | PostCSS Stringifier |
+| plugins | Array \| Object \| function | PostCSS Plugins |
+
diff --git a/lib/Error.js b/lib/Error.js
deleted file mode 100644
index 05ea46ea..00000000
--- a/lib/Error.js
+++ /dev/null
@@ -1,17 +0,0 @@
-'use strict'
-
-class SyntaxError extends Error {
- constructor (err) {
- super(err)
-
- this.name = 'Syntax Error'
-
- this.message = ''
- this.message += `${this.name} \n\n(${err.line}:${err.column}) ${err.reason}`
- this.message += `\n\n${err.showSourceCode()}\n`
-
- this.stack = false
- }
-}
-
-module.exports = SyntaxError
diff --git a/lib/options.js b/lib/options.js
deleted file mode 100644
index 980e9366..00000000
--- a/lib/options.js
+++ /dev/null
@@ -1,25 +0,0 @@
-'use strict'
-
-module.exports = function parseOptions (params) {
- if (typeof params.plugins === 'function') {
- params.plugins = params.plugins.call(this, this)
- }
-
- let plugins
-
- if (typeof params.plugins === 'undefined') plugins = []
- else if (Array.isArray(params.plugins)) plugins = params.plugins
- else plugins = [ params.plugins ]
-
- const options = {}
-
- if (typeof params !== 'undefined') {
- options.parser = params.parser
- options.syntax = params.syntax
- options.stringifier = params.stringifier
- }
-
- const exec = params && params.exec
-
- return Promise.resolve({ options: options, plugins: plugins, exec: exec })
-}
diff --git a/lib/options.json b/lib/options.json
deleted file mode 100644
index e4546157..00000000
--- a/lib/options.json
+++ /dev/null
@@ -1,43 +0,0 @@
-{
- "type": "object",
- "properties": {
- "config": {
- "type": "object",
- "properties": {
- "path": {
- "type": "string"
- },
- "ctx": {
- "type": "object"
- }
- },
- "additionalProperties": false
- },
- "exec": {
- "type": "boolean"
- },
- "ident": {
- "type": "string"
- },
- "parser": {
- "type": [ "string", "object" ]
- },
- "syntax": {
- "type": [ "string", "object" ]
- },
- "stringifier": {
- "type": [ "string", "object" ]
- },
- "plugins": {
- "anyOf": [
- { "type": "array" },
- { "type": "object" },
- { "instanceof": "Function" }
- ]
- },
- "sourceMap": {
- "type": [ "string", "boolean" ]
- }
- },
- "additionalProperties": true
-}
diff --git a/package.json b/package.json
index 4d26c130..0ebf1bbb 100644
--- a/package.json
+++ b/package.json
@@ -2,35 +2,34 @@
"name": "postcss-loader",
"version": "2.1.6",
"description": "PostCSS loader for webpack",
- "main": "lib/index.js",
+ "main": "src/index.js",
"files": [
- "lib"
+ "src"
],
"engines": {
- "node": ">= 4"
+ "node": ">= 6"
},
"dependencies": {
"loader-utils": "^1.1.0",
- "postcss": "^6.0.0",
+ "postcss": "^7.0.0",
"postcss-load-config": "^2.0.0",
- "schema-utils": "^0.4.0"
+ "schema-utils": "^1.0.0"
},
"devDependencies": {
- "jest": "^22.0.0",
+ "@webpack-utilities/test": "^1.0.0-alpha.0",
+ "jest": "^23.0.0",
"jsdoc-to-markdown": "^4.0.0",
- "memory-fs": "^0.4.0",
"postcss-import": "^11.0.0",
- "postcss-js": "^1.0.0",
+ "postcss-js": "^2.0.0",
"standard": "^11.0.0",
"standard-version": "^4.0.0",
"sugarss": "^1.0.0",
- "util.promisify": "^1.0.0",
- "webpack": "^3.0.0"
+ "webpack": "^4.0.0"
},
"scripts": {
"lint": "standard --env jest",
- "test": "jest --env=node --verbose --coverage",
- "docs": "jsdoc2md lib/index.js > LOADER.md",
+ "test": "jest --env node --verbose --coverage",
+ "docs": "jsdoc2md src/*.js > docs/LOADER.md",
"clean": "rm -rf coverage test/outputs",
"release": "standard-version"
},
diff --git a/src/Error.js b/src/Error.js
new file mode 100644
index 00000000..db05aac3
--- /dev/null
+++ b/src/Error.js
@@ -0,0 +1,37 @@
+/**
+ * **PostCSS Syntax Error**
+ *
+ * Loader wrapper for postcss syntax errors
+ *
+ * @class SyntaxError
+ * @extends Error
+ *
+ * @param {Object} err CssSyntaxError
+ */
+class SyntaxError extends Error {
+ constructor (error) {
+ super(error)
+
+ const { line, column, reason } = error
+
+ this.name = 'SyntaxError'
+
+ this.message = `${this.name}\n\n`
+
+ if (typeof line !== 'undefined') {
+ this.message += `(${line}:${column}) `
+ }
+
+ this.message += `${reason}`
+
+ const code = error.showSourceCode()
+
+ if (code) {
+ this.message += `\n\n${code}\n`
+ }
+
+ this.stack = false
+ }
+}
+
+module.exports = SyntaxError
diff --git a/src/Warning.js b/src/Warning.js
new file mode 100644
index 00000000..2355f4f5
--- /dev/null
+++ b/src/Warning.js
@@ -0,0 +1,31 @@
+/**
+ * **PostCSS Plugin Warning**
+ *
+ * Loader wrapper for postcss plugin warnings (`root.messages`)
+ *
+ * @class Warning
+ * @extends Error
+ *
+ * @param {Object} warning PostCSS Warning
+ */
+class Warning extends Error {
+ constructor (warning) {
+ super(warning)
+
+ const { text, line, column } = warning
+
+ this.name = 'Warning'
+
+ this.message = `${this.name}\n\n`
+
+ if (typeof line !== 'undefined') {
+ this.message += `(${line}:${column}) `
+ }
+
+ this.message += `${text}`
+
+ this.stack = false
+ }
+}
+
+module.exports = Warning
diff --git a/lib/index.js b/src/index.js
similarity index 64%
rename from lib/index.js
rename to src/index.js
index 5dc545e2..bb576c32 100644
--- a/lib/index.js
+++ b/src/index.js
@@ -1,46 +1,29 @@
-'use strict'
-
const path = require('path')
-const loaderUtils = require('loader-utils')
-
-const parseOptions = require('./options')
+const { getOptions } = require('loader-utils')
const validateOptions = require('schema-utils')
const postcss = require('postcss')
const postcssrc = require('postcss-load-config')
-const SyntaxError = require('./Error')
+const Warning = require('./Warning.js')
+const SyntaxError = require('./Error.js')
+const parseOptions = require('./options.js')
/**
- * PostCSS Loader
- *
- * > Loads && processes CSS with [PostCSS](https://github.com/postcss/postcss)
- *
- * @author Andrey Sitnik (@ai)