diff --git a/.editorconfig b/.editorconfig
index e2cb9700..2229196d 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -2,7 +2,7 @@ root = true
[*]
indent_style = space
-indent_size = 4
+indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
diff --git a/.gitignore b/.gitignore
index 8640e6fb..d1413baa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,15 @@
-node_modules/
+# OS
+
+.DS_Store
+._*
+
+# NODEJS
+
npm-debug.log
yarn-error.log
-build/
+
+dmd
+jest
+coverage
+jsdoc-api
+node_modules
diff --git a/.npmignore b/.npmignore
index adb6a25b..61f6bc72 100644
--- a/.npmignore
+++ b/.npmignore
@@ -1,14 +1,24 @@
+# FILES
+
+.travis.yml
.gitignore
.npmignore
.editorconfig
-node_modules/
+.travis.yml
+
npm-debug.log
-yarn-error.log
+
yarn.lock
+yarn-error.log
-build/
-test/
-.travis.yml
-gulpfile.js
+# DIRECTORIES
+
+.github
+
+dmd
+test
+coverage
+jsdoc-api
+node_modules
diff --git a/.travis.yml b/.travis.yml
index 878478bb..5fccdcd4 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,6 +1,13 @@
+cache:
+ yarn: true
+ directories:
+ - node_modules
+
language: node_js
-cache: yarn
node_js:
- - stable
- - "6"
- - "4"
+ - "node"
+ - 6
+ - 4
+
+notifications:
+ email: false
diff --git a/LICENSE b/LICENSE
index 1ae47a20..c6bb2fc6 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
-The MIT License (MIT)
+License (MIT)
-Copyright 2014 Andrey Sitnik
-[PostCSS] loader for [webpack] to postprocesses your CSS with [PostCSS plugins].
-
-[PostCSS plugins]: https://github.com/postcss/postcss#plugins
-[PostCSS]: https://github.com/postcss/postcss
-[webpack]: http://webpack.github.io/
-[ci-img]: https://travis-ci.org/postcss/postcss-loader.svg
-[ci]: https://travis-ci.org/postcss/postcss-loader
+Loader for [webpack] to process CSS with [PostCSS]
+
+[PostCSS]: https://github.com/postcss/postcss
+[webpack]: http://webpack.js.org/
## Install
-```sh
-npm install postcss-loader --save-dev
+```bash
+npm i -D postcss-loader
```
## Usage
-Create `postcss.config.js`:
-
+**postcss.config.js**
```js
-module.exports = {
- plugins: [
- require('postcss-smart-import')({ /* ...options */ }),
- require('precss')({ /* ...options */ }),
- require('autoprefixer')({ /* ...options */ })
- ]
-}
+module.exports = (ctx) => ({
+ plugins: {
+ 'postcss-import': {},
+ 'autoprefixer': {}
+ 'cssnano': {}
+ }
+})
```
You could put different configs in different directories. For example,
-global config in `project/postcss.config.js` and override its plugins
-in `project/src/legacy/postcss.config.js`.
+global config in the root of your project `./postcss.config.js` and override it
+in `./src/legacy/postcss.config.js`.
-You can read more about common PostCSS config in
-[postcss-load-config](https://github.com/michael-ciniawsky/postcss-load-config).
+You can read more about common PostCSS Config [here](https://github.com/michael-ciniawsky/postcss-load-config).
-Add PostCSS Loader to `webpack.config.js`. Put it after `css-loader`
-and `style-loader`. But before `sass-loader`, if you use it.
+Add PostCSS Loader to your `webpack.config.js`. Use it standalone or put it **after** `css-loader` and `style-loader`, but **before** other preprocessor loaders e.g `sass-loader|less-loader|stylus-loader`, if you use any.
-### Webpack 2
+**webpack.config.js**
```js
module.exports = {
module: {
@@ -57,12 +54,6 @@ module.exports = {
test: /\.css$/,
use: [
'style-loader',
- {
- loader: 'css-loader',
- options: {
- importLoaders: 1
- }
- },
'postcss-loader'
]
}
@@ -71,17 +62,16 @@ module.exports = {
}
```
-### Webpack 1
-
+**webpack.config.js**
```js
module.exports = {
module: {
- loaders: [
+ rules: [
{
test: /\.css$/,
- loaders: [
+ use: [
'style-loader',
- 'css-loader?importLoaders=1',
+ { loader: 'css-loader' options: { importLoaders: 1 } },
'postcss-loader'
]
}
@@ -92,86 +82,93 @@ module.exports = {
## Options
-### Plugins
+We recommend to use `postcss.config.js`, but you can specify options
+directly in your `webpack.config.js` aswell.
+
+|Name|Default|Description|
+|:--:|:-----:|:----------|
+|`exec`|`undefined`|Enables custom parser support in `CSS-in-JS` context|
+|`config`|`undefined`|Sets `postcss.config.js` path|
+|`parser`|`undefined`|Sets custom parser|
+|`syntax`|`undefined`|Sets custom syntax|
+|`stringifier`|`undefined`|Sets custom stringifier|
+|`plugins`|`[]`|Sets plugins|
+|`sourceMap` |`false`|Enables SourceMaps|
-We recommend to use `postcss.config.js`, but also you can specify plugins
-directly in webpack config.
+### Config
-#### Webpack 2
+#### Path
+You can manually specify the path to search for `postcss.config.js` with the following setup. This is needed if you store the `postcss.config.js` in a separate e.g `/config` folder.
+
+Otherwise it is **unnecessary** to specify it.
+
+**webpack.config.js**
```js
-module.exports = {
- module: {
- rules: [
- {
- test: /\.css/,
- use: [
- …
- {
- loader: 'postcss-loader',
- options: {
- plugins: function () {
- return [
- require('precss'),
- require('autoprefixer')
- ];
- }
- }
- }
- ]
- }
- ]
+{
+ loader: 'postcss-loader'
+ options: { config: { path: 'path/to/postcss.config.js' } }
+}
+```
+
+#### Context
+
+|Name|Type|Default|Description|
+|:--:|:--:|:-----:|:----------|
+|`env`|`{String}`|`'development'`|NODE_ENV|
+|`file`|`{Object}`|`loader.resourcePath`|extname, dirname, basename|
+|`options`|`{Object}`|`{}`|Custom Context|
+
+PostCSS loader exposes context to the config file, making your `postcss.config.js` dynamic, so can use it to do some real magic ✨
+
+**postcss.config.js**
+```js
+module.exports = ({ file, options, env }) => ({
+ parser: file.extname === '.sss' ? 'sugarss' : false
+ plugins: {
+ 'postcss-import': { root: file.dirname }
+ 'postcss-modules': options.modules ? {} : false
+ 'cssnano': env === 'production' ? { safe: true } : false
}
+})
+```
+
+**webpack.config.js**
+```js
+{
+ loader: 'postcss-loader'
+ options: { config: { ctx: { modules: true } } }
}
```
-#### Webpack 1
+### Plugins
+**webpack.config.js**
```js
-module.exports = {
- module: {
- loaders: [
- {
- test: /\.css$/,
- loaders: [
- …
- 'postcss-loader'
- ]
- }
- ]
- },
- postcss: () => {
- return [
- require('precss'),
- require('autoprefixer')
- ];
+{
+ loader: 'postcss-loader',
+ options: {
+ plugins: (ctx) => [ require('postcss-import')({ root: ctx.resourcePath }) ]
}
}
```
### Syntaxes
-PostCSS can transforms styles in any syntax, not only in CSS.
-There are 3 parameters to control syntax:
-
-* `syntax` accepts module name with `parse` and `stringify` function.
-* `parser` accepts module name with input parser function.
-* `stringifier` accepts module name with output stringifier function.
+|Name|Type|Default|Description|
+|:--:|:--:|:-----:|:----------|
+|`syntax`|`{String/Function}`|`undefined`|Custom PostCSS Syntax|
+|`parser`|`{String/Function}`|`undefined`|Custom PostCSS Parser|
+|`stringifier`|`{String/Function}`|`undefined`|Custom PostCSS Stringifier|
+**webpack.config.js**
```js
-module.exports = {
- module: {
- loaders: [
- {
- test: /\.sss/,
- loaders: [
- 'style-loader',
- 'css-loader?importLoaders=1',
- 'postcss-loader?parser=sugarss'
- ]
- }
- ]
- }
+{
+ test: /\.sss/,
+ use: [
+ 'style-loader',
+ { loader: 'postcss-loader' options: { parser: 'sugarss' } }
+ ]
}
```
@@ -183,132 +180,154 @@ You can set this `sourceMap` parameter to `inline` value to put source maps
into CSS annotation comment:
```js
-module.exports = {
- module: {
- loaders: [
- {
- test: '\/.css',
- loaders: [
- 'style-loader',
- 'css-loader?importLoaders=1',
- 'postcss-loader?sourceMap=inline'
- ]
- }
- ]
- }
+{
+ test: /\.css/,
+ use: [
+ 'style-loader',
+ { loader: 'css-loader' options: { sourceMap: true } },
+ { loader: 'postcss-loader' options: { sourceMap: true } },
+ { loader: 'sass-loader' options: { sourceMap: true } }
+ ]
}
```
## Examples
+### Stylelint
+
+**webpack.config.js**
+```js
+{
+ test: /\.css$/,
+ use: [
+ 'style-loader',
+ {
+ loader: 'postcss-loader',
+ options: {
+ plugins: [
+ require('postcss-import')()
+ require('stylelint')()
+ ]
+ }
+ }
+ ]
+}
+```
+
### CSS Modules
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**
```js
-…
- {
- test: /\.css$/,
- loaders: [
- 'style-loader',
- 'css-loader?modules&importLoaders=1',
- 'postcss-loader'
- ]
- }
-…
+{
+ test: /\.css$/,
+ use: [
+ 'style-loader',
+ { loader: 'css-loader' options: { modules: true, importLoaders: 1 } },
+ 'postcss-loader'
+ ]
+}
```
-or use [postcss-modules] plugin instead of `css-loader`.
+or use [postcss-modules] instead of `css-loader`.
[`importLoaders`]: https://github.com/webpack/css-loader#importing-and-chained-loaders
-[postcss-modules]: https://github.com/outpunk/postcss-modules
[cannot be used]: https://github.com/webpack/css-loader/issues/137
[CSS Modules]: https://github.com/webpack/css-loader#css-modules
+[postcss-modules]: https://github.com/outpunk/postcss-modules
-### JS Styles
+### CSS-in-JS
If you want to process styles written in JavaScript
you can use the [postcss-js] parser.
+
+[postcss-js]: https://github.com/postcss/postcss-js
+
```js
-…
- {
- test: /\.style.js$/,
- loaders: [
- 'style-loader',
- 'css-loader?modules&importLoaders=1',
- 'postcss-loader?parser=postcss-js',
- 'babel'
- ]
- }
-…
+{
+ test: /\.style.js$/,
+ use: [
+ 'style-loader',
+ { loader: 'postcss-loader', options: { parser: 'postcss-js' } },
+ 'babel-loader'
+ ]
+}
```
As result you will be able to write styles as:
```js
-import colors from './config/colors'
+import colors from './styles/colors'
export default {
- '.menu': {
- color: colors.main,
- height: 25,
- '&_link': {
+ '.menu': {
+ color: colors.main,
+ height: 25,
+ '&_link': {
color: 'white'
}
}
}
```
-> If you are using Babel >= v6 you need to do the following in order for the setup to work
+> :warning: If you are using Babel you need to do the following in order for the setup to work
> 1. Add [babel-plugin-add-module-exports] to your configuration
> 2. You need to have only one **default** export per style module
-If you use JS styles without `postcss-js` parser, you can add `exec` parameter:
+If you use JS styles without `postcss-js` parser, you can add the `exec` parameter
```js
-…
- {
- test: /\.style.xyz$/,
- loaders: [
- 'style-loader',
- 'css-loader?modules&importLoaders=1',
- 'postcss-loader?parser=custom-parser&exec'
- ]
- }
-…
+{
+ test: /\.style.js$/,
+ use: [
+ 'style-loader',
+ { loader: 'postcss-loader', options: { parser: 'sugarss', exec: true } }
+ ]
+}
```
[postcss-js]: https://github.com/postcss/postcss-js
[babel-plugin-add-module-exports]: https://github.com/59naga/babel-plugin-add-module-exports
-### Dynamic Config
+### [Extract CSS][ExtractPlugin]
-PostCSS loader sends a loaded instance to PostCSS common config.
-You can use it to do some real magic:
+[ExtractPlugin]: https://github.com/webpack-contrib/extract-text-webpack-plugin
+**webpack.config.js**
```js
-module.exports = function (ctx) {
- if (check(ctx.webpack.resourcePath)) {
- return { plugins: plugins1 };
- } else {
- return { plugins: plugins2 };
- }
+const ExtractTextPlugin = require('extract-text-webpack-plugin')
+
+module.exports = {
+ module: {
+ rules: [
+ {
+ test: /\.css$/,
+ use: ExtractTextPlugin.extract({
+ fallback: 'style-loader',
+ use: [
+ { loader: 'postcss-loader', options: { plugins: [...plugins] } }
+ ]
+ })
+ }
+ ]
+ },
+ plugins: [
+ new ExtractTextPlugin('[name].css')
+ ]
}
```
-### Webpack Events
+### webpack Plugin
-Webpack provides webpack plugin developers a convenient way
-to hook into the build pipeline. The postcss-loader makes use
-of this event system to allow building integrated postcss-webpack tools.
+Webpack provides webpack plugin developers a convenient way to hook into the build pipeline. The postcss-loader makes use of this event system to allow building integrated postcss-webpack tools.
See the [example] implementation.
-Event `postcss-loader-before-processing` is fired before processing and allows
-to add or remove postcss plugins.
+Event `postcss-loader-before-processing` is fired before processing and allows to add or remove PostCSS Plugins.
[example]: https://github.com/postcss/postcss-loader/blob/master/test/webpack-plugins/rewrite.js
diff --git a/error.js b/error.js
deleted file mode 100644
index 12b276bc..00000000
--- a/error.js
+++ /dev/null
@@ -1,19 +0,0 @@
-function PostCSSLoaderError(error) {
- Error.call(this);
- Error.captureStackTrace(this, PostCSSLoaderError);
- this.name = 'Syntax Error';
- this.error = error.input.source;
- this.message = error.reason;
- if ( error.line ) {
- this.message += ' (' + error.line + ':' + error.column + ')';
- }
- if ( error.line && error.input.source ) {
- this.message += '\n\n' + error.showSourceCode() + '\n';
- }
- this.hideStack = true;
-}
-
-PostCSSLoaderError.prototype = Object.create(Error.prototype);
-PostCSSLoaderError.prototype.constructor = PostCSSLoaderError;
-
-module.exports = PostCSSLoaderError;
diff --git a/gulpfile.js b/gulpfile.js
deleted file mode 100644
index ba6b6b79..00000000
--- a/gulpfile.js
+++ /dev/null
@@ -1,44 +0,0 @@
-var gulp = require('gulp');
-var path = require('path');
-var fs = require('fs-extra');
-
-var BUILD_CONFIGS = fs.readdirSync(path.join(__dirname, 'test'))
- .filter(function (file) {
- return file.indexOf('.config.') !== -1;
- }).map(function (file) {
- return file.replace('.config.js', '');
- });
-
-gulp.task('clean', function (done) {
- fs.remove(path.join(__dirname, 'build'), done);
-});
-
-gulp.task('lint', function () {
- if ( parseInt(process.versions.node) < 4 ) {
- return false;
- }
- var eslint = require('gulp-eslint');
- return gulp.src(['index.js', 'test/**/*.js', '*.js'])
- .pipe(eslint())
- .pipe(eslint.format())
- .pipe(eslint.failAfterError());
-});
-
-BUILD_CONFIGS.forEach(function (config) {
- gulp.task(config, ['clean'], function () {
- var webpack = require('webpack-stream');
- var file = path.join(__dirname, 'test', config + '.config.js');
- return gulp.src('')
- .pipe(webpack(require(file)))
- .pipe(gulp.dest('build/'));
- });
-});
-
-gulp.task('build', BUILD_CONFIGS);
-
-gulp.task('test', ['build'], function () {
- var jest = require('gulp-jest').default;
- return gulp.src('build').pipe(jest());
-});
-
-gulp.task('default', ['lint', 'test']);
diff --git a/index.js b/index.js
index daf0026f..cf5ffc56 100644
--- a/index.js
+++ b/index.js
@@ -1,154 +1,142 @@
-const path = require('path');
-const loaderUtils = require('loader-utils');
+'use strict'
-const postcss = require('postcss');
-const postcssrc = require('postcss-load-config');
+const path = require('path')
-const PostCSSLoaderError = require('./error');
+const loaderUtils = require('loader-utils')
-function parseOptions(params) {
- if (typeof params === 'function') {
- params = params.call(this, this);
- }
-
- console.log('params', params);
-
- let plugins;
-
- if (typeof params === 'undefined') {
- plugins = [];
- } else if (Array.isArray(params)) {
- plugins = params;
- } else {
- plugins = params.plugins || params.defaults;
- }
-
- console.log('plugins', plugins);
-
- let options = {};
+const parseOptions = require('./lib/options')
+const validateOptions = require('schema-utils')
- if (typeof params !== 'undefined') {
- options.parser = params.parser;
- options.syntax = params.syntax;
- options.stringifier = params.stringifier;
- }
-
- // console.log('options', options);
+const postcss = require('postcss')
+const postcssrc = require('postcss-load-config')
- let exec = params && params.exec;
-
- // console.log('exec', exec);
-
- return Promise.resolve({ options: options, plugins: plugins, exec: exec });
-}
+const SyntaxError = require('./lib/Error')
+/**
+ * PostCSS Loader
+ *
+ * > Loader for [webpack](https://github.com/webpack/webpack) to process CSS with [PostCSS]
+ *
+ * @method loader
+ *
+ * @param {String} css Source
+ * @param {Object} map Source Map
+ *
+ * @return {cb} cb Result
+ */
module.exports = function (css, map) {
- if (this.cacheable) this.cacheable();
-
- const loader = this;
+ const loader = this
- const file = loader.resourcePath;
- const params = loaderUtils.getOptions(loader) || {};
+ const cb = loader.async()
+ const file = loader.resourcePath
- const settings = params.plugins || loader.options.postcss;
+ const options = loaderUtils.getOptions(loader) || {}
- const callback = loader.async();
+ validateOptions('./lib/options.json', options, 'PostCSS Loader')
- let rc;
- let context = {
+ const rc = {
+ path: '',
+ ctx: {
+ file: {
extname: path.extname(file),
dirname: path.dirname(file),
- basename: path.basename(file),
- webpack: { watch: loader.addDependency }
- };
+ basename: path.basename(file)
+ }
+ }
+ }
- params.config ?
- rc = path.resolve(params.config) :
- rc = path.dirname(file);
+ if (options.config) {
+ options.config.path
+ ? rc.path = path.resolve(options.config.path)
+ : rc.path = path.dirname(file)
- Promise.resolve().then(() => {
- if (typeof settings !== 'undefined') {
- return parseOptions.call(loader, settings);
- }
+ options.config.ctx
+ ? rc.ctx.options = options.config.ctx
+ : rc.ctx.options = {}
+ }
- return postcssrc(context, rc, { argv: false });
- }).then((config) => {
- if (!config) config = {};
+ delete options.config
- if (config.file) loader.addDependency(config.file);
+ const sourceMap = options.sourceMap
- console.log('Config Plugins', config.plugins);
+ delete options.sourceMap
- let plugins = config.plugins || [];
+ Promise.resolve().then(() => {
+ if (Object.keys(options).length !== 0) {
+ return parseOptions.call(loader, options)
+ }
- console.log('Plugins', plugins);
- console.log('webpack Version', process.env.WEBPACK_VERSION);
+ return postcssrc(rc.ctx, rc.path, { argv: false })
+ }).then((config) => {
+ if (!config) config = {}
+
+ if (config.file) loader.addDependency(config.file)
+
+ let plugins = config.plugins || []
+ let options = Object.assign({
+ to: file,
+ from: file,
+ map: sourceMap
+ ? sourceMap === 'inline'
+ ? { inline: true, annotation: false }
+ : { inline: false, annotation: false }
+ : false
+ }, config.options)
+
+ if (options.parser === 'postcss-js') {
+ css = loader.exec(css, loader.resource)
+ }
- let options = Object.assign({}, config.options, {
- from: file,
- to: file,
- map: {
- inline: params.sourceMap === 'inline',
- annotation: false
- }
- });
+ if (typeof options.parser === 'string') {
+ options.parser = require(options.parser)
+ }
- if (typeof map === 'string') map = JSON.parse(map);
- if (map && map.mappings) options.map.prev = map;
+ if (typeof options.syntax === 'string') {
+ options.syntax = require(options.syntax)
+ }
- if (typeof options.syntax === 'string') {
- options.syntax = require(options.syntax);
- }
+ if (typeof options.stringifier === 'string') {
+ options.stringifier = require(options.stringifier)
+ }
- if (typeof options.parser === 'string') {
- options.parser = require(options.parser);
- }
+ // Loader Exec (Deprecated)
+ // https://webpack.js.org/api/loaders/#deprecated-context-properties
+ if (config.exec) {
+ css = loader.exec(css, loader.resource)
+ }
- if (typeof options.stringifier === 'string') {
- options.stringifier = require(options.stringifier);
- }
+ // Loader Plugin (Deprecated)
+ // https://webpack.js.org/api/loaders/#deprecated-context-properties
+ if (loader._compilation) {
+ plugins = loader._compilation.applyPluginsWaterfall(
+ 'postcss-loader-before-processing',
+ [].concat(plugins),
+ options
+ )
+ }
- // console.log('Options', options);
+ if (typeof map === 'string') map = JSON.parse(map)
+ if (map && map.mappings) options.map.prev = map
- let exec = options.exec || config.exec;
+ return postcss(plugins)
+ .process(css, options)
+ .then((result) => {
+ result.warnings().forEach((msg) => loader.emitWarning(msg.toString()))
- if (options.parser === 'postcss-js' || exec) {
- css = loader.exec(css, loader.resource);
- }
+ result.messages.forEach((msg) => {
+ if (msg.type === 'dependency') loader.addDependency(msg.file)
+ })
+
+ css = result.css
+ map = result.map ? result.map.toJSON() : null
- // Allow plugins to add or remove postcss plugins
- if ( loader._compilation ) {
- plugins = loader._compilation.applyPluginsWaterfall(
- 'postcss-loader-before-processing',
- [].concat(plugins),
- options
- );
+ if (loader.loaderIndex === 0) {
+ return cb(null, `module.exports = ${JSON.stringify(css)}`, map)
}
- return postcss(plugins)
- .process(css, options)
- .then((result) => {
- result.warnings().forEach((msg) => {
- loader.emitWarning(msg.toString());
- });
-
- result.messages.forEach((msg) => {
- if (msg.type === 'dependency') {
- loader.addDependency(msg.file);
- }
- });
-
- callback(
- null, result.css, result.map ? result.map.toJSON() : null
- );
-
- // console.log('Index', loader.loaderIndex);
-
- return null;
- });
- }).catch((error) => {
- return error.name === 'CssSyntaxError' ?
- callback(new PostCSSLoaderError(error)) :
- callback(error);
- });
-};
+ return cb(null, css, map, { ast: result.root })
+ })
+ }).catch((err) => {
+ return err.name === 'CssSyntaxError' ? cb(new SyntaxError(err)) : cb(err)
+ })
+}
diff --git a/lib/error.js b/lib/error.js
new file mode 100644
index 00000000..37247d7c
--- /dev/null
+++ b/lib/error.js
@@ -0,0 +1,24 @@
+'use strict'
+
+class SyntaxError extends Error {
+ constructor (err) {
+ super(err)
+
+ this.err = err.input.source
+
+ this.name = 'Syntax Error'
+ this.message = ''
+
+ if (err.line) {
+ this.message += `${this.name} \n\n(${err.line}:${err.column}) ${err.reason}`
+ }
+
+ if (err.input.source) {
+ this.message += `\n\n${err.showSourceCode()}\n`
+ }
+
+ this.stack = false
+ }
+}
+
+module.exports = SyntaxError
diff --git a/lib/options.js b/lib/options.js
new file mode 100644
index 00000000..f7e0ddbd
--- /dev/null
+++ b/lib/options.js
@@ -0,0 +1,25 @@
+'use strict'
+
+module.exports = function parseOptions (params) {
+ if (typeof params === 'function') {
+ params = params.call(this, this)
+ }
+
+ let plugins
+
+ if (typeof params === 'undefined') plugins = []
+ else if (Array.isArray(params)) plugins = params
+ 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
new file mode 100644
index 00000000..29d12972
--- /dev/null
+++ b/lib/options.json
@@ -0,0 +1,36 @@
+{
+ "type": "object",
+ "properties": {
+ "config": {
+ "type": "object",
+ "properties": {
+ "path": {
+ "type": "string"
+ },
+ "ctx": {
+ "type": "object"
+ }
+ },
+ "additionalProperties": false
+ },
+ "parser": {
+ "type": "string"
+ },
+ "syntax": {
+ "type": "string"
+ },
+ "stringifier": {
+ "type": "string"
+ },
+ "sourceMap": {
+ "type": [ "string", "boolean" ]
+ },
+ "exec": {
+ "type": "boolean"
+ },
+ "rewrite": {
+ "type": "boolean"
+ }
+ },
+ "additionalProperties": true
+}
diff --git a/package.json b/package.json
index 823dc876..49bbab17 100644
--- a/package.json
+++ b/package.json
@@ -2,55 +2,52 @@
"name": "postcss-loader",
"version": "1.3.3",
"description": "PostCSS loader for webpack",
+ "main": "index.js",
"engines": {
- "node": ">= 4"
+ "node": ">=4"
},
- "keywords": [
- "webpack",
- "loader",
- "css",
- "postcss",
- "postcss-runner"
+ "files": [
+ "lib",
+ "index.js"
],
- "author": "Andrey Sitnik