postcss-load-config
Advanced tools
Comparing version 1.0.0-alpha4 to 1.0.0-beta
65
index.js
// ------------------------------------ | ||
// #POSTCSS - LOAD CONFIG | ||
// #POSTCSS - LOAD CONFIG - INDEX | ||
// ------------------------------------ | ||
@@ -7,18 +7,61 @@ | ||
var config = require('cosmiconfig') | ||
const config = require('cosmiconfig') | ||
var loadOptions = require('postcss-load-options/lib/loadOptions.js') | ||
var loadPlugins = require('postcss-load-plugins/lib/loadPlugins.js') | ||
const loadOptions = require('postcss-load-options/lib/options.js') | ||
const loadPlugins = require('postcss-load-plugins/lib/plugins.js') | ||
module.exports = function loadConfig (options) { | ||
return config('postcss') | ||
.catch(function (error) { | ||
console.log(error) | ||
/** | ||
* @author Michael Ciniawsky (@michael-ciniawsky) <michael.ciniawsky@gmail.com> | ||
* @description Autoload Config for PostCSS | ||
* | ||
* @module postcss-load-config | ||
* @version 1.0.0 | ||
* | ||
* @requires comsiconfig | ||
* @requires postcss-load-options | ||
* @requires postcss-load-plugins | ||
* | ||
* @method postcssrc | ||
* | ||
* @param {Object} ctx Context | ||
* @param {String} path Config Directory | ||
* @param {Object} options Config Options | ||
* | ||
* @return {Promise} config PostCSS Plugins, PostCSS Options | ||
*/ | ||
module.exports = function postcssrc (ctx, path, options) { | ||
const defaults = { | ||
cwd: process.cwd(), | ||
env: process.env.NODE_ENV | ||
} | ||
ctx = Object.assign(defaults, ctx) || defaults | ||
path = path || process.cwd() | ||
options = options || {} | ||
return config('postcss', options) | ||
.load(path) | ||
.then(function (result) { | ||
result = result.config || {} | ||
return result | ||
}) | ||
.then(function (result) { | ||
.then(function (config) { | ||
if (typeof config === 'function') { | ||
config = config(ctx) | ||
} else { | ||
config = Object.assign(config, ctx) | ||
} | ||
if (!config.plugins) { | ||
config.plugins = [] | ||
} | ||
return { | ||
plugins: loadPlugins(result.config, options), | ||
options: loadOptions(result.config, options) | ||
plugins: loadPlugins(config), | ||
options: loadOptions(config) | ||
} | ||
}) | ||
.catch(function (err) { | ||
console.log(err) | ||
}) | ||
} |
{ | ||
"name": "postcss-load-config", | ||
"version": "1.0.0-alpha4", | ||
"version": "1.0.0-beta", | ||
"description": "Autoload Config for PostCSS", | ||
"engines": {"node": ">=4"}, | ||
"engines": { "node": ">=4", "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/pkg/index.js test/rc/index.js test/js/index.js", | ||
"logs": "standard-changelog > CHANGELOG.md", | ||
"docs": "jsdoc2md index.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", | ||
"postcss-load-options": "^1.0.0-alpha4", | ||
"postcss-load-plugins": "^2.0.0-alpha4" | ||
"cosmiconfig": "^2.0.2", | ||
"postcss-load-options": "^1.0.1", | ||
"postcss-load-plugins": "^2.0.0-beta" | ||
}, | ||
"devDependencies": { | ||
"ava": "^0.15.2", | ||
"coveralls": "^2.11.9", | ||
"nyc": "^6.6.1", | ||
"postcss": "^5.0.21", | ||
"postcss-bem": "^0.4.1", | ||
"ava": "^0.16.0", | ||
"coveralls": "^2.11.14", | ||
"cssnano": "^3.7.7", | ||
"jsdoc-to-markdown": "^2.0.0", | ||
"nyc": "^8.3.1", | ||
"postcss": "^5.2.4", | ||
"postcss-import": "^8.1.2", | ||
"postcss-nested": "^1.0.0", | ||
"standard": "^7.1.2", | ||
"sugarss": "^0.1.3" | ||
"postcss-scss": "^0.3.1", | ||
"standard": "^8.4.0", | ||
"sugarss": "^0.2.0" | ||
}, | ||
@@ -34,3 +38,3 @@ "ava": { | ||
"all": true, | ||
"include": ["test"], | ||
"include": ["index.js"], | ||
"extension": [".js"] | ||
@@ -40,3 +44,3 @@ }, | ||
"postcss", | ||
"postcssconfig" | ||
"postcss-config" | ||
], | ||
@@ -47,2 +51,8 @@ "author": { | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "Mateusz Derks", | ||
"url": "http://ertrzyiks.me" | ||
} | ||
], | ||
"repository": { | ||
@@ -49,0 +59,0 @@ "type": "git", |
371
README.md
@@ -1,11 +0,15 @@ | ||
[![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 Options" src="http://michael-ciniawsky.github.io/postcss-load-options/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> | ||
<img width="100" height="100" title="Load Plugins" src="http://michael-ciniawsky.github.io/postcss-load-plugins/logo.svg"> | ||
<h1>Load Config</h1> | ||
@@ -15,3 +19,3 @@ <p>Autoload Config for PostCSS<p> | ||
## Install | ||
<h2 align="center">Install</h2> | ||
@@ -22,89 +26,132 @@ ```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": { | ||
"parser": "sugarss", | ||
"map": false, | ||
"from": "/path/to/src.sss", | ||
"to": "/path/to/dest.css", | ||
"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 | ||
``` | ||
```json | ||
{ | ||
"parser": "sugarss", | ||
"map": false, | ||
"from": "/path/to/src.sss", | ||
"to": "/path/to/dest.css", | ||
"plugins": { | ||
"postcss-plugin": {} | ||
} | ||
} | ||
``` | ||
### `postcss.config.js` | ||
Create a **`postcss.config.js`** file. | ||
``` | ||
App | ||
|– client | ||
|– public | ||
| | ||
|- postcss.config.js | ||
|- package.json | ||
``` | ||
```js | ||
postcss: { | ||
parser: require('sugarss'), | ||
from: 'app.sss' | ||
map: 'inline', | ||
to: 'app.css' | ||
module.exports = (ctx) => { | ||
parser: ctx.sugar ? 'sugarss' : false, | ||
map: ctx.env === 'development' ? ctx.map : false, | ||
from: ctx.from | ||
to: ctx.to | ||
plugins: { | ||
'postcss-plugin1': null, | ||
'postcss-plugin2': null, | ||
'postcss-plugin3': {option1: '', option2: ''} | ||
'postcss-plugin': ctx.plugin | ||
} | ||
} | ||
``` | ||
// Loaded Options Setup | ||
{ | ||
parser: require('sugarss'), | ||
from: 'app.sss' | ||
map: 'inline', | ||
to: 'app.css' | ||
```js | ||
module.exports = (ctx) => { | ||
parser: ctx.sugar ? 'sugarss' : false, | ||
map: ctx.env === 'development' ? ctx.map : false, | ||
from: ctx.from | ||
to: ctx.to | ||
plugins: [ | ||
require('postcss-plugin')(ctx.plugin) | ||
] | ||
} | ||
// Loaded Plugin Setup | ||
[ | ||
require('postcss-plugin1')(), | ||
require('postcss-plugin2')(), | ||
require('postcss-plugin3')(options) | ||
] | ||
``` | ||
## Examples | ||
#### package.json | ||
<h2 align="center">Options</h2> | ||
```json | ||
Plugin **options** can take the following values. | ||
**`null`**: Plugin loads with defaults. | ||
```js | ||
'postcss-plugin': null | ||
``` | ||
**`[Object]`**: Plugin loads with given 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 | ||
{ | ||
"dependencies": { | ||
"sugarss": "^0.1.4", | ||
"postcss-bem": "^0.2.2", | ||
"postcss-nested": "^1.0.0", | ||
"postcss-import": "^8.1.2" | ||
}, | ||
"postcss": { | ||
"parser": "sugarss", | ||
"from": "app.sss", | ||
"map": "inline", | ||
"to": "app.css", | ||
"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': false, // plugins[0] | ||
'postcss-plugin': false, // plugins[1] | ||
'postcss-plugin': {} // plugins[2] | ||
} | ||
@@ -114,119 +161,123 @@ } | ||
#### postcss.config.js | ||
### Context | ||
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. | ||
<h2 align="center">Examples</h2> | ||
**postcss.config.js** | ||
```js | ||
module.exports = { | ||
parser: "sugarss", | ||
from: 'app.sss', | ||
map: 'inline', | ||
to: 'app.css', | ||
module.exports = (ctx) => { | ||
parser: ctx.sugar ? 'sugarss' : false, | ||
map: ctx.env === 'development' ? ctx.map : false, | ||
from: ctx.from | ||
to: ctx.to | ||
plugins: { | ||
'postcss-import': null, | ||
'postcss-nested': null, | ||
'postcss-bem': { | ||
style: 'bem', | ||
separators: { | ||
namespace: '-', | ||
descendent: '__', | ||
modifier: '--' | ||
}, | ||
shortcuts: { | ||
component: 'block', | ||
descendent: 'elem', | ||
modifier: 'mods' | ||
} | ||
} | ||
postcss-import: null, | ||
postcss-nested: null, | ||
cssnano: ctx.env === 'development' ? false : null | ||
} | ||
} | ||
``` | ||
#### postcssrc.json | ||
### <img width="80" height="80" src="https://worldvectorlogo.com/logos/nodejs-icon.svg"> | ||
```json | ||
{ | ||
"parser": "sugarss", | ||
"from": "app.sss", | ||
"map": "inline", | ||
"to": "app.css", | ||
"plugins": { | ||
"postcss-import": null, | ||
"postcss-nested": null, | ||
"postcss-bem": { | ||
"style": "bem", | ||
"separators": { | ||
"namespace": "-", | ||
"descendent":"__", | ||
"modifier": "--" | ||
}, | ||
"shortcuts": { | ||
"component": "block", | ||
"descendent": "elem", | ||
"modifier": "mods" | ||
} | ||
} | ||
} | ||
"scripts": { | ||
"build": "NODE_ENV=production node postcss", | ||
"start": "NODE_ENV=development node postcss" | ||
} | ||
``` | ||
## Usage | ||
#### Default | ||
```js | ||
'use strict' | ||
const { readFileSync } = require('fs') | ||
const postcss = require('postcss') | ||
const postcssrc = require('postcss-load-config')() | ||
const postcssrc = require('postcss-load-config') | ||
const css = readFileSync('./index.css', 'utf8') | ||
const css = readFileSync('index.sss', 'utf8') | ||
postcssrc.then(({ plugins, options }) => { | ||
const ctx = { map: 'inline' from: '/index.sss', to: '/index.css' } | ||
postcssrc(ctx).then(({ plugins, options }) => { | ||
postcss(plugins) | ||
.process(css, options) | ||
.then(result => console.log(result.css)) | ||
.then(({ css }) => console.log(css)) | ||
})) | ||
``` | ||
#### Custom | ||
### <img width="80" height="80" src="https://worldvectorlogo.com/logos/gulp.svg"> | ||
```json | ||
"scripts": { | ||
"build": "NODE_ENV=production gulp", | ||
"start": "NODE_ENV=development gulp" | ||
} | ||
``` | ||
```js | ||
'use strict' | ||
const { task, src, dest } = require('gulp') | ||
const { readFileSync } = require('fs') | ||
const postcss = require('gulp-postcssrc') | ||
const postcss = require('postcss') | ||
const postcssrc = require('postcss-load-config')('./path/to/postcssrc.json') | ||
task('css', () => { | ||
src('src/*.css') | ||
.pipe(postcss()) | ||
.pipe(dest('dest')) | ||
}) | ||
const css = readFileSync('./index.css', 'utf8') | ||
postcssrc.then(({ plugins, options }) => { | ||
postcss(plugins) | ||
.process(css, options) | ||
.then(result => console.log(result.css)) | ||
})) | ||
task('default', ['css']) | ||
``` | ||
## LICENSE | ||
### <img width="80" height="80" src="https://worldvectorlogo.com/logos/webpack.svg"> | ||
> License (MIT) | ||
```json | ||
"scripts": { | ||
"build": "NODE_ENV=production webpack", | ||
"start": "NODE_ENV=development webpack-dev-server" | ||
} | ||
``` | ||
> Copyright (c) 2016 Michael Ciniawsky | ||
```js | ||
module.exports = (env) => { | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.css$/ | ||
use: [ | ||
'style-loader', | ||
{ | ||
loader: 'css-loader', | ||
options: { importLoaders: 1 } } | ||
}, | ||
'postcss-loader' | ||
] | ||
} | ||
] | ||
} | ||
} | ||
``` | ||
> 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: | ||
<h2 align="center">Maintainers</h2> | ||
> The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
<table> | ||
<tbody> | ||
<tr> | ||
<td align="center"> | ||
<img width="150 height="150" | ||
src="https://avatars.githubusercontent.com/u/5419992?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://avatars.githubusercontent.com/u/2437969?v=3&s=150"> | ||
<br /> | ||
<a href="https://github.com/ertrzyiks">Mateusz Derks</a> | ||
</td> | ||
</tr> | ||
<tbody> | ||
</table> | ||
> 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. | ||
@@ -236,2 +287,5 @@ [npm]: https://img.shields.io/npm/v/postcss-load-config.svg | ||
[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-config.svg | ||
@@ -243,6 +297,9 @@ [deps-url]: https://david-dm.org/michael-ciniawsky/postcss-load-config | ||
[travis]: http://img.shields.io/travis/michael-ciniawsky/postcss-load-config.svg?branch=master | ||
[travis-url]: https://travis-ci.org/michael-ciniawsky/postcss-load-config?branch=master | ||
[tests]: http://img.shields.io/travis/michael-ciniawsky/postcss-load-config.svg?branch=master | ||
[tests-url]: https://travis-ci.org/michael-ciniawsky/postcss-load-config?branch=master | ||
[cover]: https://coveralls.io/repos/github/michael-ciniawsky/postcss-load-config/badge.svg?branch=master | ||
[cover-url]: https://coveralls.io/github/michael-ciniawsky/postcss-load-config?branch=master | ||
[chat]: https://img.shields.io/gitter/room/postcss/postcss.svg?maxAge=2592000 | ||
[chat-url]: https://gitter.im/postcss/postcss |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
11522
6
58
301
11
1
- Removedcosmiconfig@1.1.0(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)
Updatedcosmiconfig@^2.0.2
Updatedpostcss-load-options@^1.0.1