postcss-load-plugins
Advanced tools
Comparing version 2.0.0-alpha to 2.0.0-alpha2
// ------------------------------------ | ||
// #POSTCSS - LOAD PLUGINS | ||
// #POSTCSS - LOAD PLUGINS - LIB | ||
// ------------------------------------ | ||
@@ -12,31 +12,14 @@ | ||
options = require(path.join(process.cwd(), options)) | ||
for (let option in options) { | ||
config.plugins[option] = options.plugins[option] | ||
} | ||
} | ||
if (typeof options === 'object') { | ||
if (options) { | ||
for (let option in options) { | ||
config.plugins[option] = options.plugins[option] | ||
} | ||
} | ||
if (options === undefined) { | ||
} else { | ||
options = config.plugins | ||
} | ||
if (options === undefined) { | ||
options = [] | ||
plugins = options | ||
return plugins | ||
} | ||
function load (plugin, options) { | ||
if (options === null || options === undefined) { | ||
return require(plugin)() | ||
} | ||
return require(plugin)(options) | ||
return options === false ? require(plugin) : require(plugin)(options) | ||
} | ||
@@ -43,0 +26,0 @@ |
{ | ||
"name": "postcss-load-plugins", | ||
"version": "2.0.0-alpha", | ||
"version": "2.0.0-alpha2", | ||
"description": "Autoload Plugins for PostCSS", | ||
@@ -9,5 +9,5 @@ "engines": {"node": ">=4"}, | ||
"clean": "echo '=> Cleaning' && rm -rf .nyc_output coverage", | ||
"pretest": "echo '=> Linting' && standard", | ||
"test": "echo '=> Testing' && nyc ava 'test/*.js'", | ||
"start": "echo '=> Starting' sudo npm run clean && sudo npm test" | ||
"pretest": "echo '=> Linting' && npm run clean && standard", | ||
"test": "echo '=> Testing' && nyc ava 'test/index.js'", | ||
"start": "echo '=> Starting' && sudo npm test" | ||
}, | ||
@@ -24,29 +24,17 @@ "dependencies": { | ||
"ava": "^0.15.2", | ||
"babel-core": "^6.9.1", | ||
"babel-preset-es2015": "^6.9.0", | ||
"babel-register": "^6.9.0", | ||
"coveralls": "^2.11.9", | ||
"nyc": "^6.4.4", | ||
"nyc": "^6.6.1", | ||
"standard": "^7.1.2" | ||
}, | ||
"ava": { | ||
"babel": "inherit" | ||
"verbose": "true" | ||
}, | ||
"nyc": { | ||
"all": true, | ||
"require": "babel-register", | ||
"include": ["lib", "test"], | ||
"extension": [".js"] | ||
}, | ||
"babel": { | ||
"env": { | ||
"development": { | ||
"sourceMaps": "inline" | ||
} | ||
}, | ||
"presets": ["es2015"] | ||
}, | ||
"keywords": [ | ||
"PostCSS", | ||
"PostCSS Plugins" | ||
"postcss", | ||
"postcssplugins" | ||
], | ||
@@ -53,0 +41,0 @@ "author": { |
115
README.md
@@ -15,3 +15,3 @@ [![NPM][npm]][npm-url] | ||
## Install | ||
<h2 align="center">Install</h2> | ||
@@ -22,10 +22,8 @@ ```bash | ||
Plugins will be loaded directly from your projects ***package.json*** file. | ||
<h2 align="center">Usage</h2> | ||
Install them as usual with as deps/devDeps. | ||
Install plugin as usual and make sure saving them to your ***package.json*** dependencies and/or devDependencies. | ||
``` | ||
npm i -S postcss-plugin | ||
``` | ||
``` | ||
npm i -D postcss-plugin | ||
@@ -36,3 +34,3 @@ ``` | ||
- Create **postcss.plugins** section in your projects **package.json**. | ||
- Create **postcss** section in your projects **package.json**. | ||
- Create a **postcss.config.js** or **postcssrc.json** file. | ||
@@ -42,30 +40,35 @@ | ||
Plugin **options** can either take ```null``` or an object ```{/* options */}``` | ||
as value. | ||
Plugin **options** can either take ``` false ``` or an object literal | ||
``` {} ``` as value. | ||
```null``` : Load plugin with no options (plugin defaults). | ||
``` false ``` : Plugin loads with no options (defaults) | ||
```[Object]``` : Load plugin with given options. | ||
``` [Object] ``` : Plugin loads with set options. | ||
## Ordering | ||
## Order | ||
Plugin **order** will be determined by declaration in the plugins section. | ||
Plugin **order** is determined by declaration in the plugins section. | ||
```js | ||
plugins: { | ||
'postcss-plugin1': null, | ||
'postcss-plugin2': null, | ||
'postcss-plugin3': {/* options */} | ||
postcss: { | ||
plugins: { | ||
'postcss-plugin1': false, | ||
'postcss-plugin2': false, | ||
'postcss-plugin3': {} | ||
} | ||
} | ||
// [ | ||
require('postcss-plugin1')(), | ||
require('postcss-plugin2')(), | ||
require('postcss-plugin3')(options) | ||
] | ||
// Loaded Plugin Setup | ||
[ | ||
require('postcss-plugin1')(), | ||
require('postcss-plugin2')(), | ||
require('postcss-plugin3')(options) | ||
] | ||
``` | ||
## Examples | ||
#### package.json | ||
<h2 align="center">Examples</h2> | ||
### package.json | ||
```json | ||
@@ -80,4 +83,4 @@ { | ||
"plugins": { | ||
"postcss-import": null, | ||
"postcss-nested": null, | ||
"postcss-import": false, | ||
"postcss-nested": false, | ||
"postcss-bem": { | ||
@@ -89,8 +92,3 @@ "style": "bem", | ||
"modifier": "--" | ||
}, | ||
"shortcuts": { | ||
"component": "block", | ||
"descendent": "elem", | ||
"modifier": "mods" | ||
} | ||
} | ||
} | ||
@@ -102,3 +100,3 @@ } | ||
#### postcss.config.js | ||
### postcss.config.js | ||
@@ -108,4 +106,4 @@ ```js | ||
plugins: { | ||
'postcss-import': null, | ||
'postcss-nested': null, | ||
'postcss-import': false, | ||
'postcss-nested': false, | ||
'postcss-bem': { | ||
@@ -117,7 +115,2 @@ style: 'bem', | ||
modifier: '--' | ||
}, | ||
shortcuts: { | ||
component: 'block', | ||
descendent: 'elem', | ||
modifier: 'mods' | ||
} | ||
@@ -133,4 +126,4 @@ } | ||
"plugins": { | ||
"postcss-import": null, | ||
"postcss-nested": null, | ||
"postcss-import": false, | ||
"postcss-nested": false, | ||
"postcss-bem": { | ||
@@ -142,7 +135,2 @@ "style": "bem", | ||
"modifier": "--" | ||
}, | ||
"shortcuts": { | ||
"component": "block", | ||
"descendent": "elem", | ||
"modifier": "mods" | ||
} | ||
@@ -154,14 +142,9 @@ } | ||
## Usage | ||
#### Default | ||
```js | ||
'use strict' | ||
const { readFileSync } = require('fs') | ||
const fs = require('fs') | ||
const postcss = require('postcss') | ||
const pluginsrc = require('postcss-load-plugins')() | ||
const css = fs.readFileSync('./index.css', 'utf-8') | ||
const css = readFileSync('./index.css', 'utf8') | ||
@@ -175,26 +158,7 @@ pluginsrc.then((plugins) => { | ||
#### Custom | ||
<h2 align="center">LICENSE</h2> | ||
```js | ||
'use strict' | ||
const fs = require('fs') | ||
const postcss = require('postcss') | ||
const pluginsrc = require('postcss-load-plugins')('./path/to/postcssrc.json') | ||
const css = fs.readFileSync('./index.css', 'utf-8') | ||
pluginsrc.then((plugins) => { | ||
postcss(plugins) | ||
.process(css) | ||
.then(result => console.log(result.css)) | ||
})) | ||
``` | ||
## LICENSE | ||
> License (MIT) | ||
> Copyright (c) 2016 Michael Ciniawsky | ||
> Copyright (c) 2016 Michael Ciniawsky <michael.ciniawsky@gmail.com> | ||
@@ -222,5 +186,2 @@ > Permission is hereby granted, free of charge, to any person obtaining a copy | ||
[node]: https://img.shields.io/node/v/gh-badges.svg?maxAge=2592000 | ||
[node-url]: https://nodejs.org | ||
[deps]: https://david-dm.org/michael-ciniawsky/postcss-load-plugins.svg | ||
@@ -227,0 +188,0 @@ [deps-url]: https://david-dm.org/michael-ciniawsky/postcss-load-plugins |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
9
0
8352
36
184