Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postcss-load-plugins

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-load-plugins - npm Package Compare versions

Comparing version 2.0.1-alpha to 2.1.0

lib/plugins.js

77

index.js
// ------------------------------------
// #POSTCSS - LOAD PLUGINS
// #POSTCSS - LOAD PLUGINS - INDEX
// ------------------------------------

@@ -7,10 +7,73 @@

const config = require('cosmiconfig')
var resolve = require('path').resolve
const loadPlugins = require('./lib/loadPlugins')
var config = require('cosmiconfig')
var assign = require('object-assign')
module.exports = function (options) {
return config('postcss')
.catch((error) => console.log(error))
.then((result) => loadPlugins(result.config, options))
var loadPlugins = require('./lib/plugins')
/**
* @author Michael Ciniawsky (@michael-ciniawsky) <michael.ciniawsky@gmail.com>
* @description Autoload Plugins for PostCSS
* @license MIT
*
* @module postcss-load-plugins
* @version 1.0.0
*
* @requires cosmiconfig
* @requires object-assign
* @requires ./lib/plugins.js
*
* @method pluginsrc
*
* @param {Object} ctx Context
* @param {String} path Directory
* @param {Object} options Options
*
* @return {Array} config PostCSS Plugins
*/
module.exports = function pluginsrc (ctx, path, options) {
ctx = assign({ cwd: process.cwd(), env: process.env.NODE_ENV }, ctx)
path = path ? resolve(path) : process.cwd()
options = assign({}, options)
if (ctx.env === undefined) {
process.env.NODE_ENV = 'development'
}
var file
return config('postcss', options)
.load(path)
.then(function (result) {
if (result === undefined) {
console.log('PostCSS Plugins could not be loaded.' + path)
}
file = result ? result.filepath : ''
return result ? result.config : {}
})
.then(function (plugins) {
if (typeof plugins === 'function') {
plugins = plugins(ctx)
}
if (typeof result === 'object') {
plugins = assign(plugins, ctx)
}
if (!plugins.plugins) {
plugins.plugins = []
}
return {
plugins: loadPlugins(plugins),
file: file
}
})
.catch(function (err) {
console.log(err)
})
}

72

package.json
{
"name": "postcss-load-plugins",
"version": "2.0.1-alpha",
"version": "2.1.0",
"description": "Autoload Plugins for PostCSS",
"engines": {"node": ">=4"},
"engines": { "node": ">=0.12", "npm": ">=3" },
"main": "index.js",
"scripts": {
"clean": "echo '=> Cleaning' && rm -rf .nyc_output coverage",
"pretest": "echo '=> Linting' && npm run clean standard",
"test": "echo '=> Testing' && nyc ava 'test/index.js'",
"start": "echo '=> Starting' && sudo npm test"
"lint": "standard",
"test": "nyc ava test/err/index.js test/rc/index.js test/pkg/index.js test/js/**/index.js",
"logs": "standard-changelog > CHANGELOG.md",
"docs": "jsdoc2md index.js lib/plugins.js > INDEX.md",
"clean": "rm -rf .nyc_output coverage jsdoc-api dmd",
"start": "sudo npm run clean && npm run lint && sudo npm test"
},
"dependencies": {
"cosmiconfig": "^1.1.0"
"cosmiconfig": "^2.1.1",
"object-assign": "^4.1.0"
},
"devDependencies": {
"postcss": "^5.0.21",
"postcss-bem": "^0.4.1",
"postcss-import": "^8.1.2",
"ava": "^0.17.0",
"coveralls": "^2.11.15",
"cssnano": "^3.8.1",
"jsdoc-to-markdown": "^2.0.0",
"nyc": "^9.0.1",
"peter": "^1.0.2",
"postcss": "^5.2.6",
"postcss-cssnext": "^2.8.0",
"postcss-import": "^9.0.0",
"postcss-nested": "^1.0.0",
"sugarss": "^0.1.3",
"ava": "^0.15.2",
"babel-core": "^6.10.4",
"babel-preset-es2015": "^6.9.0",
"babel-register": "^6.9.0",
"coveralls": "^2.11.9",
"nyc": "^6.6.1",
"standard": "^7.1.2"
"postcss-sprites": "^4.0.0",
"standard": "^8.6.0",
"standard-changelog": "0.0.1",
"sugarss": "^0.2.0"
},
"ava": {
"babel": "inherit"
"verbose": "true"
},
"nyc": {
"all": true,
"require": "babel-register",
"include": ["lib", "test"],
"include": ["index.js", "lib"],
"extension": [".js"]
},
"babel": {
"env": {
"development": {
"sourceMaps": "inline"
}
},
"presets": ["es2015"]
},
"files": [
"lib",
"index.js"
],
"keywords": [
"PostCSS",
"PostCSS Plugins"
"postcss",
"postcss-plugin"
],

@@ -55,2 +55,12 @@ "author": {

},
"contributors": [
{
"name": "Mateusz Derks",
"url": "http://ertrzyiks.me"
},
{
"name": "Diogo Franco",
"email": "diogomfranco@gmail.com"
}
],
"repository": {

@@ -57,0 +67,0 @@ "type": "git",

@@ -1,10 +0,13 @@

[![NPM][npm]][npm-url]
[![Deps][deps]][deps-url]
[![Tests][travis]][travis-url]
[![Coverage][cover]][cover-url]
[![Standard Code Style][style]][style-url]
[![npm][npm]][npm-url]
[![node][node]][node-url]
[![deps][deps]][deps-url]
[![tests][tests]][tests-url]
[![coverage][cover]][cover-url]
[![code style][style]][style-url]
[![chat][chat]][chat-url]
<div align="center">
<img width="100" height="100" title="Load Plugins" src="http://michael-ciniawsky.github.io/postcss-load-plugins/logo.svg">
<a href="https://github.com/postcss/postcss">
<img width="108" height="108" title="PostCSS" src="http://postcss.github.io/postcss/logo.svg" hspace="20">
<img width="110" height="110" title="PostCSS" src="http://postcss.github.io/postcss/logo.svg" hspace="10">
</a>

@@ -15,3 +18,3 @@ <h1>Load Plugins</h1>

## Install
<h2 align="center">Install</h2>

@@ -22,74 +25,75 @@ ```bash

## Usage
Install plugin as usual and make sure saving them to your ***package.json*** dependencies and/or devDependencies.
<h2 align="center">Usage</h2>
```
npm i -S postcss-plugin
npm i -D postcss-plugin
npm i -S|-D postcss-plugin
```
After installing your plugins there a two common ways to declare your plugins and options.
Install plugins and save them to your ***package.json*** dependencies/devDependencies.
- Create **postcss** section in your projects **package.json**.
- Create a **postcss.config.js** or **postcssrc.json** file.
### `package.json`
## Options
Create **`postcss`** section in your projects **`package.json`**.
Plugin **options** can either take ```null``` or an object literal ```{}```
as value.
```
App
|– client
|– public
|
|- package.json
```
```null``` : Plugin loads with no options (defaults).
```json
{
"postcss": {
"plugins": {
"postcss-plugin": {}
}
}
}
```
```[Object]``` : Plugin loads with set options.
### `.postcssrc`
## Ordering
Create a **`.postcssrc`** file.
Plugin **order** is determined by declaration in the plugins section.
```
App
|– client
|– public
|
|-.postcssrc
|- package.json
```
```js
postcss: {
plugins: {
'postcss-plugin1': null,
'postcss-plugin2': null,
'postcss-plugin3': {option1: '', option2: ''}
```json
{
"plugins": {
"postcss-plugin": {}
}
}
```
// Loaded Plugin Setup
### `postcss.config.js`
[
require('postcss-plugin1')(),
require('postcss-plugin2')(),
require('postcss-plugin3')(options)
]
Create a **`postcss.config.js`** file.
```
App
|– client
|– public
|
|- postcss.config.js
|- package.json
```
## Examples
#### package.json
Plugins can be loaded in either using an `{Object}` or an `{Array}`.
```json
{
"dependencies": {
"postcss-bem": "^0.2.2",
"postcss-nested": "^1.0.0",
"postcss-import": "^8.1.2"
},
"postcss": {
"plugins": {
"postcss-import": null,
"postcss-nested": null,
"postcss-bem": {
"style": "bem",
"separators": {
"namespace": "-",
"descendent":"__",
"modifier": "--"
},
"shortcuts": {
"component": "block",
"descendent": "elem",
"modifier": "mods"
}
}
##### `{Object}`
```js
module.exports = (ctx) => {
return {
plugins: {
'postcss-plugin': ctx.plugin
}

@@ -100,45 +104,48 @@ }

#### postcss.config.js
##### `{Array}`
```js
module.exports = {
plugins: {
'postcss-import': null,
'postcss-nested': null,
'postcss-bem': {
style: 'bem',
separators: {
namespace: '-',
descendent: '__',
modifier: '--'
},
shortcuts: {
component: 'block',
descendent: 'elem',
modifier: 'mods'
}
}
module.exports = (ctx) => {
return {
plugins: [
require('postcss-plugin')(ctx.plugin)
]
}
}
```
#### postcssrc.json
```json
<h2 align="center">Options</h2>
Plugin **options** can take the following values.
**`{}`: Plugin loads with defaults**
```js
'postcss-plugin': {} || null
```
> :warning: `{}` must be an **empty** object
**`{Object}`: Plugin loads with options**
```js
'postcss-plugin': { option: '', option: '' }
```
**`false`: Plugin will not be loaded**
```js
'postcss-plugin': false
```
### Order
Plugin **order** is determined by declaration in the plugins section.
```js
{
"plugins": {
"postcss-import": null,
"postcss-nested": null,
"postcss-bem": {
"style": "bem",
"separators": {
"namespace": "-",
"descendent":"__",
"modifier": "--"
},
"shortcuts": {
"component": "block",
"descendent": "elem",
"modifier": "mods"
}
}
plugins: {
'postcss-plugin': {}, // plugins[0]
'postcss-plugin': {}, // plugins[1]
'postcss-plugin': {} // plugins[2]
}

@@ -148,78 +155,97 @@ }

## Usage
#### Default
### Context
```js
'use strict'
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.
const { readFileSync } = require('fs')
<h2 align="center">Examples</h2>
const postcss = require('postcss')
const pluginsrc = require('postcss-load-plugins')()
**`postcss.config.js`**
const css = readFileSync('./index.css', 'utf8')
pluginsrc.then((plugins) => {
postcss(plugins)
.process(css)
.then(result => console.log(result.css))
}))
```js
module.exports = (ctx) => {
return {
plugins: {
postcss-import: {},
postcss-modules: ctx.modules ? {} : false,
cssnano: ctx.env === 'production' ? {} : false
}
}
}
```
#### Custom
### <img width="80" height="80" src="https://worldvectorlogo.com/logos/nodejs-icon.svg">
```js
'use strict'
const { readFileSync } = require('fs')
const postcss = require('postcss')
const pluginsrc = require('postcss-load-plugins')('./path/to/postcssrc.json')
const pluginsrc = require('postcss-load-plugins')
const css = fs.readFileSync('./index.css', 'utf8')
const css = readFileSync('index.css', 'utf8')
pluginsrc.then((plugins) => {
const ctx = { modules: true }
pluginsrc(ctx).then((plugins) => {
postcss(plugins)
.process(css)
.then(result => console.log(result.css))
}))
.then(({ css }) => console.log(css))
})
```
## LICENSE
<h2 align="center">Maintainers</h2>
> License (MIT)
<table>
<tbody>
<tr>
<td align="center">
<img width="150" height="150"
src="https://github.com/michael-ciniawsky.png?v=3&s=150">
<br>
<a href="https://github.com/michael-ciniawsky">Michael Ciniawsky</a>
</td>
<td align="center">
<img width="150" height="150"
src="https://github.com/ertrzyiks.png?v=3&s=150">
<br>
<a href="https://github.com/ertrzyiks">Mateusz Derks</a>
</td>
</tr>
</tbody>
</table>
> Copyright (c) 2016 Michael Ciniawsky
<h2 align="center">Contributors</h2>
> Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
<table>
<tbody>
<tr>
<td align="center">
<img width="150" height="150"
src="https://github.com/Kovensky.png?v=3&s=150">
<br>
<a href="https://github.com/Kovensky">Diogo Franco</a>
</td>
</tr>
</tbody>
</table>
> The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
[npm]: https://img.shields.io/npm/v/postcss-load-plugins.svg
[npm-url]: https://npmjs.com/package/postcss-load-plugins
[node]: https://img.shields.io/node/v/postcss-load-plugins.svg
[node-url]: https://nodejs.org/
[deps]: https://david-dm.org/michael-ciniawsky/postcss-load-plugins.svg
[deps-url]: https://david-dm.org/michael-ciniawsky/postcss-load-plugins
[tests]: http://img.shields.io/travis/michael-ciniawsky/postcss-load-plugins.svg
[tests-url]: https://travis-ci.org/michael-ciniawsky/postcss-load-plugins
[cover]: https://coveralls.io/repos/github/michael-ciniawsky/postcss-load-plugins/badge.svg
[cover-url]: https://coveralls.io/github/michael-ciniawsky/postcss-load-plugins
[style]: https://img.shields.io/badge/code%20style-standard-yellow.svg
[style-url]: http://standardjs.com/
[travis]: http://img.shields.io/travis/michael-ciniawsky/postcss-load-plugins.svg
[travis-url]: https://travis-ci.org/michael-ciniawsky/postcss-load-plugins
[cover]: https://coveralls.io/repos/github/michael-ciniawsky/postcss-load-plugins/badge.svg?branch=master
[cover-url]: https://coveralls.io/github/michael-ciniawsky/postcss-load-plugins?branch=master
[chat]: https://img.shields.io/gitter/room/postcss/postcss.svg
[chat-url]: https://gitter.im/postcss/postcss

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc