Skip to content

Commit

Permalink
Merge f0f15c8 into c9a1b42
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathantneal committed Feb 13, 2018
2 parents c9a1b42 + f0f15c8 commit 4d11ca6
Show file tree
Hide file tree
Showing 7 changed files with 345 additions and 233 deletions.
2 changes: 1 addition & 1 deletion .babelrc
@@ -1,5 +1,5 @@
{
"presets": ["es2015-loose", "stage-0"],
"presets": ["env"],
"plugins": ["add-module-exports"],
"env": {
"development": {
Expand Down
11 changes: 3 additions & 8 deletions .travis.yml
@@ -1,14 +1,9 @@
sudo: false
# https://docs.travis-ci.com/user/travis-lint

language: node_js
matrix:
include:
- node_js: '5'
- node_js: '4'
- node_js: '0.12'
env: NO_ESLINT=true

script: "[[ $NO_ESLINT == true ]] && npm run test-012 || npm test"
node_js:
- 4

after_success:
- './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls'
8 changes: 8 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,11 @@
# 3.0.0

* postcss-use now uses commas instead of semicolons to separate options in
order to support PostCSS 6.
* Removed: Dependencies on `balanced-match` and `lodash.isplainobject`.
* Updated: `postcss` from 5 to 6.
* Updated: `resolve-from` from 2 to 4.

# 2.3.0

* postcss-use now accepts an object of default options to supply to plugins
Expand Down
243 changes: 162 additions & 81 deletions README.md
@@ -1,132 +1,213 @@
# [postcss][postcss]-use [![Build Status](https://travis-ci.org/postcss/postcss-use.svg?branch=master)][ci]
# PostCSS Use [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS Logo" width="90" height="90" align="right">][postcss]

> Enable PostCSS plugins directly in your stylesheet.
[![NPM Version][npm-img]][npm-url]
[![Build Status][cli-img]][cli-url]
[![Gitter Chat][git-img]][git-url]

## Install
[PostCSS Use] lets you require PostCSS plugins from within CSS.

With [npm](https://npmjs.org/package/postcss-use) do:
```css
@use postcss-discard-comments;

/* test */

h1 {
color: red
}

/* becomes */

h1 {
color: red
}
```
npm install postcss-use --save

## Usage

Add [PostCSS Use] to your build tool:

```bash
npm install postcss-use --save-dev
```

## Example
#### Node

Both hash maps and arrays are supported; note that functions are not, for
security reasons. A hash map uses the CSS format of
`option: value; option2: value2`, but please note that *values* must be valid
JSON syntax. For example if a module takes a string option, it must be wrapped
in quotation marks.
Use [PostCSS Use] to process your CSS:

### Input
```js
import postcssUse from 'postcss-use';

#### Standard syntax
postcssUse.process(YOUR_CSS);
```

With [postcss-discard-comments]:
#### PostCSS

```css
@use postcss-discard-comments(removeAll: true);
/*! test */
h1 {
color: red
}
Add [PostCSS] to your build tool:

```bash
npm install postcss --save-dev
```

#### Alternative syntax
Use [PostCSS Use] as a plugin:

You may also use configuration blocks that are more *CSS-like*. Note that array
options cannot be parsed by this method.
```js
import postcss from 'gulp-postcss';
import postcssUse from 'postcss-use';

```css
@use postcss-discard-comments {
removeAll: true
}
postcss([
postcssUse()
]).process(YOUR_CSS);
```

### Output
#### Gulp

```css
h1 {
color: red
}
Add [Gulp PostCSS] to your build tool:

```bash
npm install gulp-postcss --save-dev
```

## API
Use [PostCSS Use] in your Gulpfile:

### use(options)
```js
import postcss from 'gulp-postcss';
import postcssUse from 'postcss-use';

gulp.task('css', () => gulp.src('./src/*.css').pipe(
postcss([
postcssUse()
])
).pipe(
gulp.dest('.')
));
```

#### options
#### Grunt

##### modules
Add [Grunt PostCSS] to your build tool:

Type: `array|string`
*Required option*.
```bash
npm install grunt-postcss --save-dev
```

You must specify this array of postcss plugins to use, for security purposes.
This prevents malicious usage of postcss-use in browser environments.
Use [PostCSS Use] in your Gruntfile:

```js
postcss([ use({ modules: ['autoprefixer', 'cssnano', 'cssnext']}) ]);
import postcssUse from 'postcss-use';

grunt.loadNpmTasks('grunt-postcss');

grunt.initConfig({
postcss: {
options: {
use: [
postcssUse()
]
},
dist: {
src: '*.css'
}
}
});
```

Note that you may also set this option to `'*'` to disable whitelisting of
modules. This is not recommended for environments where you may be accepting
arbitrary user input; use at your own risk.
## Passing Options into Plugins

##### resolveFromFile
Options may be passed into plugins as a JSON object, an array, a hash map, or
as declarations. A hash map will follow the format of
`option: value, option2: value2`.

Type: `boolean` (default: `false`)
The following examples are equivalent.

Set this to true in order to resolve plugins relative to the file that
referenced them. This enables the usage of different versions of the same
plugin, for instance.
```css
@use postcss-preset-env(removeAll: true);

```js
postcss([ use({ resolveFromFile: true, modules: '*' }) ]);
@use postcss-discard-comments(removeAll: true);

@use postcss-discard-comments({ removeAll: true });

@use postcss-discard-comments { removeAll: true }
```

##### options
## Options

Type: `object` (default: `{}`)
### modules

Default options for plugins, keyed by plugin name. If both the default and the specified options are objects, they are merged. Otherwise, the options specified in the CSS are used.
The `modules` option specifies a list of allowable PostCSS Plugins, expressed
as a `String`, `Array`, or `RegExp`. By default, all plugins are disabled in
order to prevent malicious usage in browser environments.

```js
postcss([
use({
modules: '*',
options: {
autoprefixer: {
browsers: ['> 1%', 'IE 7']
}
}
})
]);
postcssUse({
// allow plugins starting with autoprefixer, postcss, precss, and cssnano
modules: [
/^autoprefixer/,
/^postcss/,
/^precss/,
/^cssnano/
]
})
```

## Usage
```js
postcssUse({
// allow autoprefixer, postcss-preset-env, and postcss-flexbugs-fixes
modules: [ 'autoprefixer', 'postcss-preset-env', 'postcss-flexbugs-fixes' ]
})
```

See the [PostCSS documentation](https://github.com/postcss/postcss#usage) for
examples for your environment.
Setting the option to `"*"` will allow PostCSS Use to require any plugins. This
is not recommended for environments where you may be accepting arbitrary user
input; use at your own risk.

## Contributors
```js
postcssUse({
// allow any plugin
modules: '*'
})
```

Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
### resolveFromFile

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
| [<img src="https://avatars.githubusercontent.com/u/1282980?v=3" width="100px;"/><br /><sub>Ben Briggs</sub>](http://beneb.info)<br />[💻](https://github.com/postcss/postcss-use/commits?author=ben-eb) [📖](https://github.com/postcss/postcss-use/commits?author=ben-eb) 👀 [⚠️](https://github.com/postcss/postcss-use/commits?author=ben-eb) | [<img src="https://avatars.githubusercontent.com/u/188426?v=3" width="100px;"/><br /><sub>Jonathan Neal</sub>](//jonathantneal.com)<br />[💻](https://github.com/postcss/postcss-use/commits?author=jonathantneal) [⚠️](https://github.com/postcss/postcss-use/commits?author=jonathantneal) | [<img src="https://avatars.githubusercontent.com/u/2784308?v=3" width="100px;"/><br /><sub>一丝</sub>](www.iyunlu.com/view)<br />[💻](https://github.com/postcss/postcss-use/commits?author=yisibl) | [<img src="https://avatars.githubusercontent.com/u/157534?v=3" width="100px;"/><br /><sub>Maxime Thirouin</sub>](https://moox.io/)<br />[📖](https://github.com/postcss/postcss-use/commits?author=MoOx) | [<img src="https://avatars.githubusercontent.com/u/5635476?v=3" width="100px;"/><br /><sub>Bogdan Chadkin</sub>](https://github.com/TrySound)<br />[📖](https://github.com/postcss/postcss-use/commits?author=TrySound) 👀 | [<img src="https://avatars.githubusercontent.com/u/48200?v=3" width="100px;"/><br /><sub>Espen Hovlandsdal</sub>](https://espen.codes/)<br />[💻](https://github.com/postcss/postcss-use/commits?author=rexxars) [⚠️](https://github.com/postcss/postcss-use/commits?author=rexxars) | [<img src="https://avatars.githubusercontent.com/u/19343?v=3" width="100px;"/><br /><sub>Andrey Sitnik</sub>](http://sitnik.ru)<br />👀 |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
<!-- ALL-CONTRIBUTORS-LIST:END -->
The `resolveFromFile` option specifies whether plugins should be resolved
relative to the file that referenced them. This may be used to enable the usage
of different versions of the same plugin. By default, it is disabled.

This project follows the [all-contributors] specification. Contributions of
any kind welcome!
```js
postcssUse({
resolveFromFile: true
})
```

## License
### options

MIT © [Ben Briggs](http://beneb.info)
The `options` option specifies individual options for specific plugins by
plugin name.

```js
postcssUse({
options: {
'postcss-preset-env': {
stage: 0,
browsers: 'last two versions'
}
}
})
```

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
| [<img src="https://avatars.githubusercontent.com/u/1282980?v=3" width="100px;"/><br /><sub>Ben Briggs</sub>](http://beneb.info)<br />[💻](https://github.com/postcss/postcss-use/commits?author=ben-eb) [📖](https://github.com/postcss/postcss-use/commits?author=ben-eb) 👀 [⚠️](https://github.com/postcss/postcss-use/commits?author=ben-eb) | [<img src="https://avatars.githubusercontent.com/u/188426?v=3" width="100px;"/><br /><sub>Jonathan Neal</sub>](//jonathantneal.com)<br />[💻](https://github.com/postcss/postcss-use/commits?author=jonathantneal) [⚠️](https://github.com/postcss/postcss-use/commits?author=jonathantneal) | [<img src="https://avatars.githubusercontent.com/u/2784308?v=3" width="100px;"/><br /><sub>一丝</sub>](www.iyunlu.com/view)<br />[💻](https://github.com/postcss/postcss-use/commits?author=yisibl) | [<img src="https://avatars.githubusercontent.com/u/157534?v=3" width="100px;"/><br /><sub>Maxime Thirouin</sub>](https://moox.io/)<br />[📖](https://github.com/postcss/postcss-use/commits?author=MoOx) | [<img src="https://avatars.githubusercontent.com/u/5635476?v=3" width="100px;"/><br /><sub>Bogdan Chadkin</sub>](https://github.com/TrySound)<br />[📖](https://github.com/postcss/postcss-use/commits?author=TrySound) 👀 | [<img src="https://avatars.githubusercontent.com/u/48200?v=3" width="100px;"/><br /><sub>Espen Hovlandsdal</sub>](https://espen.codes/)<br />[💻](https://github.com/postcss/postcss-use/commits?author=rexxars) [⚠️](https://github.com/postcss/postcss-use/commits?author=rexxars) | [<img src="https://avatars.githubusercontent.com/u/19343?v=3" width="100px;"/><br /><sub>Andrey Sitnik</sub>](http://sitnik.ru)<br />👀 |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
<!-- ALL-CONTRIBUTORS-LIST:END -->

[all-contributors]: https://github.com/kentcdodds/all-contributors
[ci]: https://travis-ci.org/postcss/postcss-use
[postcss]: https://github.com/postcss/postcss
[postcss-discard-comments]: https://github.com/ben-eb/postcss-discard-comments
[npm-url]: https://www.npmjs.com/package/postcss-use
[npm-img]: https://img.shields.io/npm/v/postcss-use.svg
[cli-url]: https://travis-ci.org/postcss/postcss-use
[cli-img]: https://img.shields.io/travis/postcss/postcss-use/master.svg
[git-url]: https://gitter.im/postcss/postcss
[git-img]: https://img.shields.io/badge/chat-gitter-blue.svg

[PostCSS Use]: https://github.com/postcss/postcss-use
[PostCSS]: https://github.com/postcss/postcss
[Gulp PostCSS]: https://github.com/postcss/gulp-postcss
[Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss

0 comments on commit 4d11ca6

Please sign in to comment.