Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
311 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,132 +1,190 @@ | ||
# [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; | ||
|
||
``` | ||
npm install postcss-use --save | ||
``` | ||
/* test */ | ||
|
||
## Example | ||
h1 { | ||
color: red | ||
} | ||
|
||
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. | ||
/* becomes */ | ||
|
||
### Input | ||
h1 { | ||
color: red | ||
} | ||
``` | ||
|
||
#### Standard syntax | ||
## Usage | ||
|
||
With [postcss-discard-comments]: | ||
Add [PostCSS Use] to your build tool: | ||
|
||
```css | ||
@use postcss-discard-comments(removeAll: true); | ||
/*! test */ | ||
h1 { | ||
color: red | ||
} | ||
```bash | ||
npm install postcss-use --save-dev | ||
``` | ||
|
||
#### Alternative syntax | ||
#### Node | ||
|
||
You may also use configuration blocks that are more *CSS-like*. Note that array | ||
options cannot be parsed by this method. | ||
Use [PostCSS Use] to process your CSS: | ||
|
||
```css | ||
@use postcss-discard-comments { | ||
removeAll: true | ||
} | ||
```js | ||
import postcssUse from 'postcss-use'; | ||
|
||
postcssUse.process(YOUR_CSS); | ||
``` | ||
|
||
### Output | ||
#### PostCSS | ||
|
||
```css | ||
h1 { | ||
color: red | ||
} | ||
Add [PostCSS] to your build tool: | ||
|
||
```bash | ||
npm install postcss --save-dev | ||
``` | ||
|
||
## API | ||
Use [PostCSS Use] as a plugin: | ||
|
||
### use(options) | ||
```js | ||
import postcss from 'gulp-postcss'; | ||
import postcssUse from 'postcss-use'; | ||
|
||
#### options | ||
postcss([ | ||
postcssUse() | ||
]).process(YOUR_CSS); | ||
``` | ||
|
||
#### Gulp | ||
|
||
##### modules | ||
Add [Gulp PostCSS] to your build tool: | ||
|
||
Type: `array|string` | ||
*Required option*. | ||
```bash | ||
npm install gulp-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 Gulpfile: | ||
|
||
```js | ||
postcss([ use({ modules: ['autoprefixer', 'cssnano', 'cssnext']}) ]); | ||
import postcss from 'gulp-postcss'; | ||
import postcssUse from 'postcss-use'; | ||
|
||
gulp.task('css', () => gulp.src('./src/*.css').pipe( | ||
postcss([ | ||
postcssUse() | ||
]) | ||
).pipe( | ||
gulp.dest('.') | ||
)); | ||
``` | ||
|
||
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. | ||
#### Grunt | ||
|
||
##### resolveFromFile | ||
Add [Grunt PostCSS] to your build tool: | ||
|
||
Type: `boolean` (default: `false`) | ||
```bash | ||
npm install grunt-postcss --save-dev | ||
``` | ||
|
||
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. | ||
Use [PostCSS Use] in your Gruntfile: | ||
|
||
```js | ||
postcss([ use({ resolveFromFile: true, modules: '*' }) ]); | ||
import postcssUse from 'postcss-use'; | ||
|
||
grunt.loadNpmTasks('grunt-postcss'); | ||
|
||
grunt.initConfig({ | ||
postcss: { | ||
options: { | ||
use: [ | ||
postcssUse() | ||
] | ||
}, | ||
dist: { | ||
src: '*.css' | ||
} | ||
} | ||
}); | ||
``` | ||
|
||
##### options | ||
## Passing Options into Plugins | ||
|
||
Type: `object` (default: `{}`) | ||
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`. | ||
|
||
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 following examples are equivalent. | ||
|
||
```js | ||
postcss([ | ||
use({ | ||
modules: '*', | ||
options: { | ||
autoprefixer: { | ||
browsers: ['> 1%', 'IE 7'] | ||
} | ||
} | ||
}) | ||
]); | ||
```css | ||
@use postcss-preset-env(removeAll: true); | ||
|
||
@use postcss-discard-comments(removeAll: true); | ||
|
||
@use postcss-discard-comments({ removeAll: true }); | ||
|
||
@use postcss-discard-comments { removeAll: true } | ||
``` | ||
|
||
## Usage | ||
## Options | ||
|
||
See the [PostCSS documentation](https://github.com/postcss/postcss#usage) for | ||
examples for your environment. | ||
### modules | ||
|
||
## Contributors | ||
The `modules` option specifies a list of allowable PostCSS Plugins, expressed | ||
as a `String` or an `Array` where each item is either an exact `String` or a | ||
matching `RegExp`. By default, only **postcss** prefixed plugins are allowed, | ||
in order to prevent malicious usage in browser environments. | ||
|
||
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)): | ||
```js | ||
postcssUse({ | ||
modules: [ /^postcss-[\w-]+$/ ] // <= this is the default | ||
}) | ||
``` | ||
|
||
<!-- 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 --> | ||
```js | ||
postcssUse({ | ||
modules: [ 'autoprefixer', 'postcss-preset-env', 'cssnano' ] | ||
}) | ||
``` | ||
|
||
This project follows the [all-contributors] specification. Contributions of | ||
any kind welcome! | ||
### resolveFromFile | ||
|
||
## License | ||
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. | ||
|
||
MIT © [Ben Briggs](http://beneb.info) | ||
```js | ||
postcssUse({ | ||
resolveFromFile: true | ||
}) | ||
``` | ||
|
||
### options | ||
|
||
The `options` option specifies unique options for specific plugins. | ||
|
||
```js | ||
postcssUse({ | ||
options: { | ||
'postcss-preset-env': { | ||
stage: 0, | ||
browsers: 'last two versions' | ||
} | ||
} | ||
}) | ||
``` | ||
|
||
[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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.