├── test ├── err │ ├── plugin.js │ ├── array │ │ └── postcss.config.js │ ├── object │ │ └── postcss.config.js │ └── index.js ├── pkg │ ├── fixtures │ │ ├── imports │ │ │ ├── section.sss │ │ │ └── section.css │ │ ├── index.sss │ │ └── index.css │ ├── expect │ │ ├── index.css │ │ └── index.sss │ ├── package.json │ └── index.js ├── rc │ ├── fixtures │ │ ├── imports │ │ │ ├── section.sss │ │ │ └── section.css │ │ ├── index.sss │ │ └── index.css │ ├── .postcssrc │ ├── expect │ │ ├── index.css │ │ └── index.sss │ └── index.js └── js │ ├── array │ ├── fixtures │ │ ├── imports │ │ │ ├── section.sss │ │ │ └── section.css │ │ ├── index.sss │ │ └── index.css │ ├── expect │ │ ├── index.css │ │ └── index.sss │ ├── postcss.config.js │ └── index.js │ └── object │ ├── fixtures │ ├── imports │ │ ├── section.sss │ │ └── section.css │ ├── index.sss │ └── index.css │ ├── expect │ ├── index.css │ └── index.sss │ ├── postcss.config.js │ └── index.js ├── .gitignore ├── .npmignore ├── .editorconfig ├── .travis.yml ├── LICENSE ├── INDEX.md ├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── CHANGELOG.md ├── index.js ├── logo.svg ├── package.json ├── lib └── plugins.js └── README.md /test/err/plugin.js: -------------------------------------------------------------------------------- 1 | module.exports = {} 2 | -------------------------------------------------------------------------------- /test/pkg/fixtures/imports/section.sss: -------------------------------------------------------------------------------- 1 | .import 2 | color: goldenrod 3 | -------------------------------------------------------------------------------- /test/rc/fixtures/imports/section.sss: -------------------------------------------------------------------------------- 1 | .import 2 | color: goldenrod 3 | -------------------------------------------------------------------------------- /test/js/array/fixtures/imports/section.sss: -------------------------------------------------------------------------------- 1 | .import 2 | color: goldenrod 3 | -------------------------------------------------------------------------------- /test/js/object/fixtures/imports/section.sss: -------------------------------------------------------------------------------- 1 | .import 2 | color: goldenrod 3 | -------------------------------------------------------------------------------- /test/pkg/fixtures/imports/section.css: -------------------------------------------------------------------------------- 1 | .import { 2 | color: goldenrod; 3 | } 4 | -------------------------------------------------------------------------------- /test/rc/fixtures/imports/section.css: -------------------------------------------------------------------------------- 1 | .import { 2 | color: goldenrod; 3 | } 4 | -------------------------------------------------------------------------------- /test/js/array/fixtures/imports/section.css: -------------------------------------------------------------------------------- 1 | .import { 2 | color: goldenrod; 3 | } 4 | -------------------------------------------------------------------------------- /test/js/object/fixtures/imports/section.css: -------------------------------------------------------------------------------- 1 | .import { 2 | color: goldenrod; 3 | } 4 | -------------------------------------------------------------------------------- /test/js/array/expect/index.css: -------------------------------------------------------------------------------- 1 | .import{color:#daa520}.test{color:cyan}.test__yellow{color:#ff0}.test__navy{color:navy}.test__crimson{color:crimson} -------------------------------------------------------------------------------- /test/js/array/expect/index.sss: -------------------------------------------------------------------------------- 1 | .import{color:#daa520}.test{color:cyan}.test__yellow{color:#ff0}.test__navy{color:navy}.test__crimson{color:crimson} -------------------------------------------------------------------------------- /test/js/object/expect/index.css: -------------------------------------------------------------------------------- 1 | .import{color:#daa520}.test{color:cyan}.test__yellow{color:#ff0}.test__navy{color:navy}.test__crimson{color:crimson} -------------------------------------------------------------------------------- /test/js/object/expect/index.sss: -------------------------------------------------------------------------------- 1 | .import{color:#daa520}.test{color:cyan}.test__yellow{color:#ff0}.test__navy{color:navy}.test__crimson{color:crimson} -------------------------------------------------------------------------------- /test/err/array/postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = function (ctx) { 2 | return { 3 | plugins: [ 4 | require('../plugin.js') 5 | ] 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OS 2 | 3 | .DS_Store 4 | ._* 5 | 6 | # NODEJS 7 | 8 | .nyc_output 9 | 10 | npm-debug.log 11 | 12 | dmd 13 | coverage 14 | jsdoc-api 15 | node_modules 16 | -------------------------------------------------------------------------------- /test/pkg/fixtures/index.sss: -------------------------------------------------------------------------------- 1 | @import 'imports/section.sss' 2 | 3 | .test 4 | color: cyan 5 | 6 | &__yellow 7 | color: yellow 8 | 9 | &__navy 10 | color: navy 11 | 12 | &__crimson 13 | color: crimson 14 | -------------------------------------------------------------------------------- /test/rc/fixtures/index.sss: -------------------------------------------------------------------------------- 1 | @import 'imports/section.sss' 2 | 3 | .test 4 | color: cyan 5 | 6 | &__yellow 7 | color: yellow 8 | 9 | &__navy 10 | color: navy 11 | 12 | &__crimson 13 | color: crimson 14 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # FILES 2 | 3 | .travis.yml 4 | .gitignore 5 | .editorconfig 6 | 7 | npm-debug.log 8 | 9 | # DIRECTORIES 10 | 11 | .github 12 | .nyc_output 13 | 14 | dmd 15 | test 16 | coverage 17 | jsdoc-api 18 | node_modules 19 | -------------------------------------------------------------------------------- /test/js/array/fixtures/index.sss: -------------------------------------------------------------------------------- 1 | @import 'imports/section.sss' 2 | 3 | .test 4 | color: cyan 5 | 6 | &__yellow 7 | color: yellow 8 | 9 | &__navy 10 | color: navy 11 | 12 | &__crimson 13 | color: crimson 14 | -------------------------------------------------------------------------------- /test/js/object/fixtures/index.sss: -------------------------------------------------------------------------------- 1 | @import 'imports/section.sss' 2 | 3 | .test 4 | color: cyan 5 | 6 | &__yellow 7 | color: yellow 8 | 9 | &__navy 10 | color: navy 11 | 12 | &__crimson 13 | color: crimson 14 | -------------------------------------------------------------------------------- /test/rc/.postcssrc: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": { 3 | "postcss-import": {}, 4 | "postcss-nested": {}, 5 | "postcss-sprites": {}, 6 | "postcss-cssnext": { "warnForDuplicates": false }, 7 | "cssnano": false 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_size = 2 6 | end_of_line = lf 7 | indent_style = space 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | -------------------------------------------------------------------------------- /test/pkg/fixtures/index.css: -------------------------------------------------------------------------------- 1 | @import 'imports/section.css'; 2 | 3 | .test { 4 | color: cyan; 5 | 6 | &__yellow { 7 | color: yellow; 8 | } 9 | 10 | &__navy { 11 | color: navy; 12 | } 13 | 14 | &__crimson { 15 | color: crimson; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/rc/fixtures/index.css: -------------------------------------------------------------------------------- 1 | @import 'imports/section.css'; 2 | 3 | .test { 4 | color: cyan; 5 | 6 | &__yellow { 7 | color: yellow; 8 | } 9 | 10 | &__navy { 11 | color: navy; 12 | } 13 | 14 | &__crimson { 15 | color: crimson; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/js/array/fixtures/index.css: -------------------------------------------------------------------------------- 1 | @import 'imports/section.css'; 2 | 3 | .test { 4 | color: cyan; 5 | 6 | &__yellow { 7 | color: yellow; 8 | } 9 | 10 | &__navy { 11 | color: navy; 12 | } 13 | 14 | &__crimson { 15 | color: crimson; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/js/object/fixtures/index.css: -------------------------------------------------------------------------------- 1 | @import 'imports/section.css'; 2 | 3 | .test { 4 | color: cyan; 5 | 6 | &__yellow { 7 | color: yellow; 8 | } 9 | 10 | &__navy { 11 | color: navy; 12 | } 13 | 14 | &__crimson { 15 | color: crimson; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /test/pkg/expect/index.css: -------------------------------------------------------------------------------- 1 | .import { 2 | color: goldenrod; 3 | } 4 | 5 | .test { 6 | color: cyan; 7 | } 8 | 9 | .test__yellow { 10 | color: yellow; 11 | } 12 | 13 | .test__navy { 14 | color: navy; 15 | } 16 | 17 | .test__crimson { 18 | color: crimson; 19 | } 20 | -------------------------------------------------------------------------------- /test/pkg/expect/index.sss: -------------------------------------------------------------------------------- 1 | .import { 2 | color: goldenrod; 3 | } 4 | 5 | .test { 6 | color: cyan; 7 | } 8 | 9 | .test__yellow { 10 | color: yellow; 11 | } 12 | 13 | .test__navy { 14 | color: navy; 15 | } 16 | 17 | .test__crimson { 18 | color: crimson; 19 | } 20 | -------------------------------------------------------------------------------- /test/rc/expect/index.css: -------------------------------------------------------------------------------- 1 | .import { 2 | color: goldenrod; 3 | } 4 | 5 | .test { 6 | color: cyan; 7 | } 8 | 9 | .test__yellow { 10 | color: yellow; 11 | } 12 | 13 | .test__navy { 14 | color: navy; 15 | } 16 | 17 | .test__crimson { 18 | color: crimson; 19 | } 20 | -------------------------------------------------------------------------------- /test/rc/expect/index.sss: -------------------------------------------------------------------------------- 1 | .import { 2 | color: goldenrod; 3 | } 4 | 5 | .test { 6 | color: cyan; 7 | } 8 | 9 | .test__yellow { 10 | color: yellow; 11 | } 12 | 13 | .test__navy { 14 | color: navy; 15 | } 16 | 17 | .test__crimson { 18 | color: crimson; 19 | } 20 | -------------------------------------------------------------------------------- /test/err/object/postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = function (ctx) { 2 | return { 3 | plugins: { 4 | 'no plugin': ctx.next ? false : {}, 5 | 'no plugin options': ctx.next === 2 ? false : { option: 'value' }, 6 | '../test/err/plugin.js': {} 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | node_js: 4 | - node 5 | - 6 6 | - 4 7 | 8 | cache: 9 | directories: 10 | - node_modules 11 | 12 | after_success: 13 | - './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls' 14 | 15 | notifications: 16 | email: false 17 | -------------------------------------------------------------------------------- /test/pkg/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "postcss-config", 3 | "version": "1.0.0", 4 | "postcss": { 5 | "plugins": { 6 | "postcss-import": {}, 7 | "postcss-nested": {}, 8 | "postcss-sprites": {}, 9 | "postcss-cssnext": { "warnForDuplicates": false }, 10 | "cssnano": false 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/js/object/postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = function (ctx) { 2 | return { 3 | plugins: { 4 | 'postcss-import': {}, 5 | 'postcss-nested': {}, 6 | 'postcss-sprites': {}, 7 | 'postcss-cssnext': { warnForDuplicates: false }, 8 | 'cssnano': ctx.env === 'production' ? {} : false 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/js/array/postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = function (ctx) { 2 | return { 3 | plugins: [ 4 | require('postcss-import')(), 5 | // simulate the case of require('doiuse') without actually requiring it 6 | { postcss: require('postcss-nested')() }, 7 | require('postcss-sprites')(), 8 | require('postcss-cssnext')({ warnForDuplicates: false }), 9 | ctx.env === 'production' ? require('cssnano')() : false 10 | ] 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | License (MIT) 2 | 3 | Copyright (c) Michael Ciniawsky 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /INDEX.md: -------------------------------------------------------------------------------- 1 | ## Functions 2 | 3 |
4 |
pluginsrc(ctx, path, options)Array
5 |

Autoload Plugins for PostCSS

6 |
7 |
plugins(config)Array
8 |
9 |
10 | 11 | 12 | 13 | ## pluginsrc(ctx, path, options) ⇒ Array 14 | Autoload Plugins for PostCSS 15 | 16 | **Kind**: global function 17 | **Returns**: Array - config PostCSS Plugins 18 | **Requires**: module:cosmiconfig, module:object-assign, module:./lib/plugins.js 19 | **Version**: 2.3.0 20 | **Author:** Michael Ciniawsky (@michael-ciniawsky) 21 | **License**: MIT 22 | 23 | | Param | Type | Description | 24 | | --- | --- | --- | 25 | | ctx | Object | Context | 26 | | path | String | Directory | 27 | | options | Object | Options | 28 | 29 | 30 | 31 | ## plugins(config) ⇒ Array 32 | **Kind**: global function 33 | **Returns**: Array - plugins PostCSS Plugins 34 | 35 | | Param | Type | Description | 36 | | --- | --- | --- | 37 | | config | Object | PostCSS Config | 38 | 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Problem 2 | 3 | Briefly describe the issue you are experiencing (or the feature you want to see 4 | added to the plugin). Tell us what you were trying to do and what happened 5 | instead. Remember, this is _not_ a place to ask questions. For that, go to 6 | http://gitter.im/postcss/postcss 7 | 8 | ## Details 9 | 10 | Describe in more detail the problem you have been experiencing, if necessary. 11 | 12 | ## Error Logs 13 | 14 | Create a [gist](https://gist.github.com) which is a paste of your **full** 15 | logs(_result.warnings_ (PostCSS Warnings), _result.messages_ (PostCSS Messages), 16 | _result.css_ (CSS)), and link them here. Do **not** paste your full logs here, 17 | as it will make this issue long and hard to read! If you are reporting a bug, 18 | **always** include logs! 19 | 20 | ## Issue [ Code ] 21 | 22 | Please remember that, with sample code; it's easier to reproduce bug and much 23 | faster to fix it. 24 | 25 | Please refer to a simple code example. 26 | 27 | ```bash 28 | $ git clone https://github.com// 29 | ``` 30 | 31 | ## Environment 32 | 33 | Please provide information about your environment. 34 | 35 | | OS | Node | npm | PostCSS | 36 | |:---------------:|:---------:|:---------:|:---------:| 37 | | [name][version] | [version] | [version] | [version] | 38 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Proposed changes 2 | 3 | Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue. 4 | 5 | ## Types of changes 6 | 7 | What types of changes does your code introduce 8 | _Put an `x` in the boxes that apply_ 9 | 10 | - [ ] Bug (non-breaking change which fixes an issue) 11 | - [ ] Feature (non-breaking change which adds functionality) 12 | - [ ] Breaking Change (fix or feature which changes existing functionality) 13 | 14 | ## Checklist 15 | 16 | _Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is a reminder of what we are going to look for before merging your code._ 17 | 18 | - [ ] I have read the [CONTRIBUTING](/CONTRIBUTING.md) guide 19 | - [ ] Lint and unit tests pass with my changes 20 | - [ ] I have added tests that prove my fix is effective/works 21 | - [ ] I have added necessary documentation (if appropriate) 22 | - [ ] Any dependent changes are merged and published in downstream modules 23 | 24 | ## Further comments 25 | 26 | If this is a large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc... 27 | 28 | ### Reviewers: @michael-ciniawsky, ... 29 | -------------------------------------------------------------------------------- /test/err/index.js: -------------------------------------------------------------------------------- 1 | // ------------------------------------- 2 | // # POSTCSS - LOAD PLUGINS - TEST - ERR 3 | // ------------------------------------- 4 | 5 | 'use strict' 6 | 7 | var test = require('ava') 8 | 9 | var pluginsrc = require('../..') 10 | 11 | test('No Config - {Error} - Load Plugins', function (t) { 12 | return pluginsrc({}, 'test').catch(function (err) { 13 | t.is(err.message, 'No PostCSS Config found in: /home/travis/build/michael-ciniawsky/postcss-load-plugins/test') 14 | }) 15 | }) 16 | 17 | test('No Plugin - {Error} - Load Plugins', function (t) { 18 | return pluginsrc({}, 'test/err/object').catch(function (err) { 19 | t.is(err.message, "Loading PostCSS Plugin failed: Cannot find module 'no plugin'") 20 | }) 21 | }) 22 | 23 | test('No Plugin (Options) - {Error} - Load Plugins', function (t) { 24 | var ctx = { next: 1 } 25 | 26 | return pluginsrc(ctx, 'test/err/object').catch(function (err) { 27 | t.is(err.message, "Loading PostCSS Plugin failed: Cannot find module 'no plugin options'") 28 | }) 29 | }) 30 | 31 | test('Invalid Plugin {Object} - {Error} - Load Plugins', function (t) { 32 | var ctx = { next: 2 } 33 | 34 | return pluginsrc(ctx, 'test/err/object').catch(function (err) { 35 | t.is(err.message, 'Invalid PostCSS Plugin found: [0]') 36 | }) 37 | }) 38 | 39 | test('Invalid Plugin {Array} - {Error} - Load Plugins', function (t) { 40 | var ctx = { next: 2 } 41 | 42 | return pluginsrc(ctx, 'test/err/array').catch(function (err) { 43 | t.is(err.message, 'Invalid PostCSS Plugin found: [0]') 44 | }) 45 | }) 46 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # [2.3.0](https://github.com/michael-ciniawsky/postcss-load-plugins/compare/v2.2.0...v2.3.0) (2017-02-13) 3 | 4 | 5 | ### Features 6 | 7 | * **index:** Allow extensions for .postcssrc ([65cc0d0](https://github.com/michael-ciniawsky/postcss-load-plugins/commit/65cc0d0)) 8 | 9 | 10 | 11 | 12 | # 2.2.0 (2017-01-11) 13 | 14 | 15 | ### Features 16 | 17 | * **index:** expose config file ([c643172](https://github.com/michael-ciniawsky/postcss-load-plugins/commit/c643172)) 18 | * **index:** improve error handling ([f3a4048](https://github.com/michael-ciniawsky/postcss-load-plugins/commit/f3a4048)) 19 | * **lib:** improve error handling ([a64bb03](https://github.com/michael-ciniawsky/postcss-load-plugins/commit/a64bb03)) 20 | 21 | 22 | 23 | 24 | # 2.1.0 (2016-12-05) 25 | 26 | 27 | ### Bug Fixes 28 | 29 | * **index:** set NODE_ENV if undefined ([920f806](https://github.com/michael-ciniawsky/postcss-load-plugins/commit/920f806)) 30 | * **index:** support node v0.12 ([e31fab3](https://github.com/michael-ciniawsky/postcss-load-plugins/commit/e31fab3)) 31 | * **lib/plugins:** support node v0.12 ([c440e6b](https://github.com/michael-ciniawsky/postcss-load-plugins/commit/c440e6b)) 32 | * **loadPlugins:** add object-assign polyfill ([acd3f84](https://github.com/michael-ciniawsky/postcss-load-plugins/commit/acd3f84)) 33 | * **plugins:** check for plugin.default ([024e8c7](https://github.com/michael-ciniawsky/postcss-load-plugins/commit/024e8c7)) 34 | 35 | ### Features 36 | 37 | * function support, jsdoc, cleanups ([f637d60](https://github.com/michael-ciniawsky/postcss-load-plugins/commit/f637d60)) 38 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | // ------------------------------------ 2 | // # POSTCSS - LOAD PLUGINS - INDEX 3 | // ------------------------------------ 4 | 5 | 'use strict' 6 | 7 | var resolve = require('path').resolve 8 | 9 | var config = require('cosmiconfig') 10 | var assign = require('object-assign') 11 | 12 | var loadPlugins = require('./lib/plugins') 13 | 14 | /** 15 | * Autoload Plugins for PostCSS 16 | * 17 | * @author Michael Ciniawsky (@michael-ciniawsky) 18 | * @license MIT 19 | * 20 | * @module postcss-load-plugins 21 | * @version 2.3.0 22 | * 23 | * @requires cosmiconfig 24 | * @requires object-assign 25 | * @requires ./lib/plugins.js 26 | * 27 | * @method pluginsrc 28 | * 29 | * @param {Object} ctx Context 30 | * @param {String} path Directory 31 | * @param {Object} options Options 32 | * 33 | * @return {Array} config PostCSS Plugins 34 | */ 35 | module.exports = function pluginsrc (ctx, path, options) { 36 | ctx = assign({ cwd: process.cwd(), env: process.env.NODE_ENV }, ctx) 37 | 38 | path = path ? resolve(path) : process.cwd() 39 | 40 | options = assign({ rcExtensions: true }, options) 41 | 42 | if (!ctx.env) process.env.NODE_ENV = 'development' 43 | 44 | var file 45 | 46 | return config('postcss', options) 47 | .load(path) 48 | .then(function (result) { 49 | if (!result) throw new Error('No PostCSS Config found in: ' + path) 50 | 51 | file = result ? result.filepath : '' 52 | 53 | return result ? result.config : {} 54 | }) 55 | .then(function (plugins) { 56 | if (typeof plugins === 'function') plugins = plugins(ctx) 57 | else plugins = assign(plugins, ctx) 58 | 59 | if (!plugins.plugins) plugins.plugins = [] 60 | 61 | return { plugins: loadPlugins(plugins), file: file } 62 | }) 63 | } 64 | -------------------------------------------------------------------------------- /logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "postcss-load-plugins", 3 | "version": "2.3.0", 4 | "description": "Autoload Plugins for PostCSS", 5 | "engines": { "node": ">=0.12" }, 6 | "main": "index.js", 7 | "scripts": { 8 | "lint": "standard", 9 | "test": "nyc ava -v test/err/index.js test/rc/index.js test/pkg/index.js test/js/**/index.js", 10 | "logs": "standard-changelog -i CHANGELOG.md -w", 11 | "docs": "jsdoc2md index.js lib/plugins.js > INDEX.md", 12 | "clean": "rm -rf .nyc_output coverage jsdoc-api dmd", 13 | "start": "sudo npm run clean && npm run lint && sudo npm test" 14 | }, 15 | "dependencies": { 16 | "cosmiconfig": "^4.0.0", 17 | "object-assign": "^4.1.0" 18 | }, 19 | "devDependencies": { 20 | "ava": "^0.25.0", 21 | "coveralls": "^2.11.16", 22 | "cssnano": "^3.10.0", 23 | "jsdoc-to-markdown": "^4.0.0", 24 | "nyc": "^11.0.1", 25 | "postcss": "^6.0.3", 26 | "postcss-cssnext": "^3.0.0", 27 | "postcss-import": "^11.1.0", 28 | "postcss-nested": "^1.0.0", 29 | "postcss-sprites": "^4.2.0", 30 | "standard": "^10.0.3", 31 | "standard-changelog": "1.0.8", 32 | "sugarss": "^0.2.0" 33 | }, 34 | "files": [ 35 | "lib", 36 | "index.js" 37 | ], 38 | "keywords": [ 39 | "postcss", 40 | "postcss-plugin" 41 | ], 42 | "author": { 43 | "name": "Michael Ciniawky", 44 | "email": "michael.ciniawsky@gmail.com" 45 | }, 46 | "contributors": [ 47 | { 48 | "name": "Mateusz Derks", 49 | "url": "http://ertrzyiks.me" 50 | }, 51 | { 52 | "name": "Diogo Franco", 53 | "email": "diogomfranco@gmail.com" 54 | } 55 | ], 56 | "repository": { 57 | "type": "git", 58 | "url": "https://github.com/michael-ciniawsky/postcss-load-plugins.git" 59 | }, 60 | "bugs": { 61 | "url": "https://github.com/michael-ciniawsky/postcss-load-plugins/issues" 62 | }, 63 | "homepage": "https://github.com/michael-ciniawsky/postcss-load-plugins#readme", 64 | "license": "MIT" 65 | } 66 | -------------------------------------------------------------------------------- /test/rc/index.js: -------------------------------------------------------------------------------- 1 | // ------------------------------------ 2 | // # POSTCSS - LOAD PlUGINS - TEST - RC 3 | // ------------------------------------ 4 | 5 | 'use strict' 6 | 7 | var test = require('ava') 8 | 9 | var path = require('path') 10 | var read = require('fs').readFileSync 11 | 12 | var postcss = require('postcss') 13 | var pluginsrc = require('../..') 14 | 15 | var fixture = function (file) { 16 | return read(path.join(__dirname, 'fixtures', file), 'utf8') 17 | } 18 | 19 | var expect = function (file) { 20 | return read(path.join(__dirname, 'expect', file), 'utf8') 21 | } 22 | 23 | test('.postcssrc - {Object} - Load Plugins', function (t) { 24 | return pluginsrc({}, 'test/rc').then(function (config) { 25 | var plugins = config.plugins 26 | 27 | t.is(plugins.length, 4) 28 | t.is(plugins[0].postcssPlugin, 'postcss-import') 29 | t.is(plugins[1].postcssPlugin, 'postcss-nested') 30 | t.is(plugins[2].postcssPlugin, 'postcss-sprites') 31 | t.is(plugins[3].postcssPlugin, 'postcss-cssnext') 32 | 33 | t.is(config.file, path.resolve('test/rc/.postcssrc')) 34 | }) 35 | }) 36 | 37 | test('.postcssrc - {Object} - Process CSS', function (t) { 38 | return pluginsrc({}, 'test/rc').then(function (config) { 39 | var plugins = config.plugins 40 | 41 | var options = { 42 | from: 'test/rc/fixtures/index.css', 43 | to: 'test/rc/expect/index.css' 44 | } 45 | 46 | return postcss(plugins) 47 | .process(fixture('index.css'), options) 48 | .then(function (result) { 49 | t.is(expect('index.css'), result.css) 50 | }) 51 | }) 52 | }) 53 | 54 | test('.postcssrc - {Object} - Process SSS', function (t) { 55 | return pluginsrc({}, 'test/rc').then(function (config) { 56 | var plugins = config.plugins 57 | 58 | var options = { 59 | parser: require('sugarss'), 60 | from: 'test/rc/fixtures/index.sss', 61 | to: 'test/rc/expect/index.sss' 62 | } 63 | 64 | return postcss(plugins) 65 | .process(fixture('index.sss'), options) 66 | .then(function (result) { 67 | t.is(expect('index.sss'), result.css) 68 | }) 69 | }) 70 | }) 71 | -------------------------------------------------------------------------------- /test/pkg/index.js: -------------------------------------------------------------------------------- 1 | // ------------------------------------- 2 | // # POSTCSS - LOAD PlUGINS - TEST - PKG 3 | // ------------------------------------- 4 | 5 | 'use strict' 6 | 7 | var test = require('ava') 8 | 9 | var path = require('path') 10 | var read = require('fs').readFileSync 11 | 12 | var postcss = require('postcss') 13 | var pluginsrc = require('../..') 14 | 15 | var fixture = function (file) { 16 | return read(path.join(__dirname, 'fixtures', file), 'utf8') 17 | } 18 | 19 | var expect = function (file) { 20 | return read(path.join(__dirname, 'expect', file), 'utf8') 21 | } 22 | 23 | test('package.json - {Object} - Load Plugins', function (t) { 24 | return pluginsrc({}, 'test/pkg').then(function (config) { 25 | var plugins = config.plugins 26 | 27 | t.is(plugins.length, 4) 28 | t.is(plugins[0].postcssPlugin, 'postcss-import') 29 | t.is(plugins[1].postcssPlugin, 'postcss-nested') 30 | t.is(plugins[2].postcssPlugin, 'postcss-sprites') 31 | t.is(plugins[3].postcssPlugin, 'postcss-cssnext') 32 | 33 | t.is(config.file, path.resolve('test/pkg/package.json')) 34 | }) 35 | }) 36 | 37 | test('package.json - {Object} - Process CSS', function (t) { 38 | return pluginsrc({}, 'test/pkg').then(function (config) { 39 | var plugins = config.plugins 40 | 41 | var options = { 42 | from: 'test/pkg/fixtures/index.css', 43 | to: 'test/pkg/expect/index.css' 44 | } 45 | 46 | return postcss(plugins) 47 | .process(fixture('index.css'), options) 48 | .then(function (result) { 49 | t.is(expect('index.css'), result.css) 50 | }) 51 | }) 52 | }) 53 | 54 | test('package.json - {Object} - Process SSS', function (t) { 55 | return pluginsrc({}, 'test/pkg').then(function (config) { 56 | var plugins = config.plugins 57 | 58 | var options = { 59 | parser: require('sugarss'), 60 | from: 'test/pkg/fixtures/index.sss', 61 | to: 'test/pkg/expect/index.sss' 62 | } 63 | 64 | return postcss(plugins) 65 | .process(fixture('index.sss'), options) 66 | .then(function (result) { 67 | t.is(expect('index.sss'), result.css) 68 | }) 69 | }) 70 | }) 71 | -------------------------------------------------------------------------------- /lib/plugins.js: -------------------------------------------------------------------------------- 1 | // ------------------------------------ 2 | // # POSTCSS - LOAD PLUGINS - PLUGINS 3 | // ------------------------------------ 4 | 5 | 'use strict' 6 | 7 | /** 8 | * @method plugins 9 | * 10 | * @param {Object} config PostCSS Config 11 | * 12 | * @return {Array} plugins PostCSS Plugins 13 | */ 14 | module.exports = function plugins (config) { 15 | var plugins = [] 16 | 17 | if (Array.isArray(config.plugins)) { 18 | plugins = config.plugins.filter(Boolean) 19 | 20 | if (plugins.length && plugins.length > 0) { 21 | plugins.forEach(function (plugin, i) { 22 | if (!plugin) throw new Error('Loading PostCSS Plugin failed') 23 | 24 | if (plugin.postcss) plugin = plugin.postcss 25 | 26 | if (plugin.default) plugin = plugin.default 27 | 28 | if ( 29 | !(typeof plugin === 'object' && Array.isArray(plugin.plugins) || 30 | typeof plugin === 'function') 31 | ) { 32 | throw new TypeError('Invalid PostCSS Plugin found: ' + '[' + i + ']') 33 | } 34 | }) 35 | } 36 | 37 | return plugins 38 | } else { 39 | config = config.plugins 40 | 41 | var load = function (plugin, options) { 42 | if (options === null || Object.keys(options).length === 0) { 43 | try { 44 | return require(plugin) 45 | } catch (err) { 46 | err.message = 'Loading PostCSS Plugin failed: ' + err.message 47 | 48 | throw err 49 | } 50 | } else { 51 | try { 52 | return require(plugin)(options) 53 | } catch (err) { 54 | err.message = 'Loading PostCSS Plugin failed: ' + err.message 55 | 56 | throw err 57 | } 58 | } 59 | } 60 | 61 | Object.keys(config) 62 | .filter(function (plugin) { 63 | return config[plugin] !== false ? plugin : '' 64 | }) 65 | .forEach(function (plugin, i) { 66 | plugin = load(plugin, config[plugin]) 67 | 68 | if (plugin.postcss) plugin = plugin.postcss 69 | 70 | if (plugin.default) plugin = plugin.default 71 | 72 | if ( 73 | !(typeof plugin === 'object' && Array.isArray(plugin.plugins) || 74 | typeof plugin === 'function') 75 | ) { 76 | throw new TypeError('Invalid PostCSS Plugin found: ' + '[' + i + ']') 77 | } 78 | 79 | return plugins.push(plugin) 80 | }) 81 | 82 | return plugins 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /test/js/object/index.js: -------------------------------------------------------------------------------- 1 | // ------------------------------------ 2 | // # POSTCSS - LOAD PlUGINS - TEST - JS 3 | // ------------------------------------ 4 | 5 | 'use strict' 6 | 7 | var test = require('ava') 8 | 9 | var path = require('path') 10 | var read = require('fs').readFileSync 11 | 12 | var postcss = require('postcss') 13 | var pluginsrc = require('../../..') 14 | 15 | var fixture = function (file) { 16 | return read(path.join(__dirname, 'fixtures', file), 'utf8') 17 | } 18 | 19 | var expect = function (file) { 20 | return read(path.join(__dirname, 'expect', file), 'utf8') 21 | } 22 | 23 | test('postcss.config.js - {Function} - Load Plugins', function (t) { 24 | return pluginsrc({}, 'test/js/object').then(function (config) { 25 | var plugins = config.plugins 26 | 27 | t.is(plugins.length, 4) 28 | t.is(plugins[0].postcssPlugin, 'postcss-import') 29 | t.is(plugins[1].postcssPlugin, 'postcss-nested') 30 | t.is(plugins[2].postcssPlugin, 'postcss-sprites') 31 | t.is(plugins[3].postcssPlugin, 'postcss-cssnext') 32 | 33 | t.is(config.file, path.resolve('test/js/object/postcss.config.js')) 34 | }) 35 | }) 36 | 37 | test('postcss.config.js - {Function} - Load Plugins', function (t) { 38 | process.env.NODE_ENV = 'production' 39 | 40 | return pluginsrc({}, 'test/js/object').then(function (config) { 41 | var plugins = config.plugins 42 | 43 | t.is(plugins.length, 5) 44 | t.is(plugins[0].postcssPlugin, 'postcss-import') 45 | t.is(plugins[1].postcssPlugin, 'postcss-nested') 46 | t.is(plugins[2].postcssPlugin, 'postcss-sprites') 47 | t.is(plugins[3].postcssPlugin, 'postcss-cssnext') 48 | t.is(plugins[4].postcssPlugin, 'cssnano') 49 | 50 | t.is(config.file, path.resolve('test/js/object/postcss.config.js')) 51 | }) 52 | }) 53 | 54 | test('postcss.config.js - {Function} - Process CSS', function (t) { 55 | return pluginsrc({}, 'test/js/object').then(function (config) { 56 | var plugins = config.plugins 57 | 58 | var options = { 59 | from: 'test/js/object/fixtures/index.css', 60 | to: 'test/js/object/expect/index.css' 61 | } 62 | 63 | return postcss(plugins) 64 | .process(fixture('index.css'), options) 65 | .then(function (result) { 66 | t.is(expect('index.css'), result.css) 67 | }) 68 | }) 69 | }) 70 | 71 | test('postcss.config.js - {Function} - Process SSS', function (t) { 72 | return pluginsrc({}, 'test/js/object').then(function (config) { 73 | var plugins = config.plugins 74 | 75 | var options = { 76 | parser: require('sugarss'), 77 | from: 'test/js/object/fixtures/index.sss', 78 | to: 'test/js/object/expect/index.sss' 79 | } 80 | 81 | return postcss(plugins) 82 | .process(fixture('index.sss'), options) 83 | .then(function (result) { 84 | t.is(expect('index.sss'), result.css) 85 | }) 86 | }) 87 | }) 88 | -------------------------------------------------------------------------------- /test/js/array/index.js: -------------------------------------------------------------------------------- 1 | // ------------------------------------ 2 | // # POSTCSS - LOAD PlUGINS - TEST - JS 3 | // ------------------------------------ 4 | 5 | 'use strict' 6 | 7 | var test = require('ava') 8 | 9 | var path = require('path') 10 | var read = require('fs').readFileSync 11 | 12 | var postcss = require('postcss') 13 | var pluginsrc = require('../../..') 14 | 15 | var fixture = function (file) { 16 | return read(path.join(__dirname, 'fixtures', file), 'utf8') 17 | } 18 | 19 | var expect = function (file) { 20 | return read(path.join(__dirname, 'expect', file), 'utf8') 21 | } 22 | 23 | test('postcss.config.js - {Function} - Load Plugins', function (t) { 24 | return pluginsrc({}, 'test/js/array').then(function (config) { 25 | var plugins = config.plugins 26 | 27 | t.is(plugins.length, 4) 28 | t.is(plugins[0].postcssPlugin, 'postcss-import') 29 | t.is(plugins[1].postcss.postcssPlugin, 'postcss-nested') 30 | t.is(plugins[2].postcssPlugin, 'postcss-sprites') 31 | t.is(plugins[3].postcssPlugin, 'postcss-cssnext') 32 | 33 | t.is(config.file, path.resolve('test/js/array/postcss.config.js')) 34 | }) 35 | }) 36 | 37 | test('postcss.config.js - {Function} - Load Plugins', function (t) { 38 | process.env.NODE_ENV = 'production' 39 | 40 | return pluginsrc({}, 'test/js/array').then(function (config) { 41 | var plugins = config.plugins 42 | 43 | t.is(plugins.length, 5) 44 | t.is(plugins[0].postcssPlugin, 'postcss-import') 45 | t.is(plugins[1].postcss.postcssPlugin, 'postcss-nested') 46 | t.is(plugins[2].postcssPlugin, 'postcss-sprites') 47 | t.is(plugins[3].postcssPlugin, 'postcss-cssnext') 48 | t.is(plugins[4].postcssPlugin, 'cssnano') 49 | 50 | t.is(config.file, path.resolve('test/js/array/postcss.config.js')) 51 | }) 52 | }) 53 | 54 | test('postcss.config.js - {Function} - Process CSS', function (t) { 55 | return pluginsrc({}, 'test/js/array').then(function (config) { 56 | var plugins = config.plugins 57 | 58 | var options = { 59 | from: 'test/js/array/fixtures/index.css', 60 | to: 'test/js/array/expect/index.css' 61 | } 62 | 63 | return postcss(plugins) 64 | .process(fixture('index.css'), options) 65 | .then(function (result) { 66 | t.is(expect('index.css'), result.css) 67 | }) 68 | }) 69 | }) 70 | 71 | test('postcss.config.js - {Function} - Process SSS', function (t) { 72 | return pluginsrc({}, 'test/js/array').then(function (config) { 73 | var plugins = config.plugins 74 | 75 | var options = { 76 | parser: require('sugarss'), 77 | from: 'test/js/array/fixtures/index.sss', 78 | to: 'test/js/array/expect/index.sss' 79 | } 80 | 81 | return postcss(plugins) 82 | .process(fixture('index.sss'), options) 83 | .then(function (result) { 84 | t.is(expect('index.sss'), result.css) 85 | }) 86 | }) 87 | }) 88 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![npm][npm]][npm-url] 2 | [![node][node]][node-url] 3 | [![deps][deps]][deps-url] 4 | [![tests][tests]][tests-url] 5 | [![coverage][cover]][cover-url] 6 | [![code style][style]][style-url] 7 | [![chat][chat]][chat-url] 8 | 9 |
10 | 11 | 12 | 13 | 14 |

Load Plugins

15 |
16 | 17 |

Install

18 | 19 | ```bash 20 | npm i -D postcss-load-plugins 21 | ``` 22 | 23 |

Usage

24 | 25 | ``` 26 | npm i -S|-D postcss-plugin 27 | ``` 28 | 29 | Install plugins and save them to your ***package.json*** dependencies/devDependencies. 30 | 31 | ### `package.json` 32 | 33 | Create **`postcss`** section in your projects **`package.json`**. 34 | 35 | ``` 36 | App 37 | |– client 38 | |– public 39 | | 40 | |- package.json 41 | ``` 42 | 43 | ```json 44 | { 45 | "postcss": { 46 | "plugins": { 47 | "postcss-plugin": {} 48 | } 49 | } 50 | } 51 | ``` 52 | 53 | ### `.postcssrc` 54 | 55 | Create a **`.postcssrc`** file. 56 | 57 | ``` 58 | App 59 | |– client 60 | |– public 61 | | 62 | |- (.postcssrc|.postcssrc.json|.postcssrc.yaml) 63 | |- package.json 64 | ``` 65 | 66 | **`JSON`** 67 | ```json 68 | { 69 | "plugins": { 70 | "postcss-plugin": {} 71 | } 72 | } 73 | ``` 74 | 75 | **`YAML`** 76 | ```yaml 77 | plugins: 78 | postcss-plugin: {} 79 | ``` 80 | 81 | ### `postcss.config.js` or `.postcssrc.js` 82 | 83 | You may need some JavaScript logic to generate your config. For this case you can use a file named **`postcss.config.js`** or **`.postcssrc.js`**. 84 | 85 | ``` 86 | App 87 | |– client 88 | |– public 89 | | 90 | |- (postcss.config.js|.postcssrc.js) 91 | |- package.json 92 | ``` 93 | 94 | Plugins can be loaded in either using an `{Object}` or an `{Array}`. 95 | 96 | ##### `{Object}` 97 | 98 | ```js 99 | module.exports = (ctx) => ({ 100 | plugins: { 101 | 'postcss-plugin': ctx.plugin 102 | } 103 | }) 104 | ``` 105 | 106 | ##### `{Array}` 107 | 108 | ```js 109 | module.exports = (ctx) => ({ 110 | plugins: [ 111 | require('postcss-plugin')(ctx.plugin) 112 | ] 113 | }) 114 | ``` 115 | 116 |

Options

117 | 118 | Plugin **options** can take the following values. 119 | 120 | **`{}`: Plugin loads with defaults** 121 | 122 | ```js 123 | 'postcss-plugin': {} || null 124 | ``` 125 | 126 | > :warning: `{}` must be an **empty** object 127 | 128 | **`{Object}`: Plugin loads with options** 129 | 130 | ```js 131 | 'postcss-plugin': { option: '', option: '' } 132 | ``` 133 | 134 | **`false`: Plugin will not be loaded** 135 | 136 | ```js 137 | 'postcss-plugin': false 138 | ``` 139 | 140 | ### Order 141 | 142 | Plugin **order** is determined by declaration in the plugins section. 143 | 144 | ```js 145 | { 146 | plugins: { 147 | 'postcss-plugin': {}, // plugins[0] 148 | 'postcss-plugin': {}, // plugins[1] 149 | 'postcss-plugin': {} // plugins[2] 150 | } 151 | } 152 | ``` 153 | 154 | ### Context 155 | 156 | When using a function `(postcss.config.js)`, it is possible to pass context to `postcss-load-plugins`, which will be evaluated before loading your plugins. By default `ctx.env (process.env.NODE_ENV)` and `ctx.cwd (process.cwd())` are available. 157 | 158 |

Examples

159 | 160 | **`postcss.config.js`** 161 | 162 | ```js 163 | module.exports = (ctx) => ({ 164 | plugins: { 165 | postcss-import: {}, 166 | postcss-modules: ctx.modules ? {} : false, 167 | cssnano: ctx.env === 'production' ? {} : false 168 | } 169 | }) 170 | ``` 171 | 172 | ### 173 | 174 | ```js 175 | const { readFileSync } = require('fs') 176 | 177 | const postcss = require('postcss') 178 | const pluginsrc = require('postcss-load-plugins') 179 | 180 | const css = readFileSync('index.css', 'utf8') 181 | 182 | const ctx = { modules: true } 183 | 184 | pluginsrc(ctx).then((plugins) => { 185 | postcss(plugins) 186 | .process(css) 187 | .then((result) => console.log(result.css)) 188 | }) 189 | ``` 190 | 191 |

Maintainers

192 | 193 | 194 | 195 | 196 | 202 | 208 | 209 | 210 |
197 | 199 |
200 | Michael Ciniawsky 201 |
203 | 205 |
206 | Mateusz Derks 207 |
211 | 212 |

Contributors

213 | 214 | 215 | 216 | 217 | 223 | 224 | 225 |
218 | 220 |
221 | Diogo Franco 222 |
226 | 227 | 228 | [npm]: https://img.shields.io/npm/v/postcss-load-plugins.svg 229 | [npm-url]: https://npmjs.com/package/postcss-load-plugins 230 | 231 | [node]: https://img.shields.io/node/v/postcss-load-plugins.svg 232 | [node-url]: https://nodejs.org/ 233 | 234 | [deps]: https://david-dm.org/michael-ciniawsky/postcss-load-plugins.svg 235 | [deps-url]: https://david-dm.org/michael-ciniawsky/postcss-load-plugins 236 | 237 | [tests]: http://img.shields.io/travis/michael-ciniawsky/postcss-load-plugins.svg 238 | [tests-url]: https://travis-ci.org/michael-ciniawsky/postcss-load-plugins 239 | 240 | [cover]: https://coveralls.io/repos/github/michael-ciniawsky/postcss-load-plugins/badge.svg 241 | [cover-url]: https://coveralls.io/github/michael-ciniawsky/postcss-load-plugins 242 | 243 | [style]: https://img.shields.io/badge/code%20style-standard-yellow.svg 244 | [style-url]: http://standardjs.com/ 245 | 246 | [chat]: https://img.shields.io/gitter/room/postcss/postcss.svg 247 | [chat-url]: https://gitter.im/postcss/postcss 248 | --------------------------------------------------------------------------------