Skip to content

Commit

Permalink
Merge 7e21811 into c9a1b42
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathantneal committed Feb 13, 2018
2 parents c9a1b42 + 7e21811 commit 8cbc71a
Show file tree
Hide file tree
Showing 7 changed files with 311 additions and 242 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

* Updated: `postcss` from 5.x to 6.x.
* Updated: `resolve-from` from 2.x to 4.x.
* Changed: Uses commas instead of semicolons to separate options.
* Changed: Allows `postcss-` prefixed plugins by default.
* Removed: Dependencies on `balanced-match` and `lodash.isplainobject`.

# 2.3.0

* postcss-use now accepts an object of default options to supply to plugins
Expand Down
224 changes: 141 additions & 83 deletions README.md
@@ -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
49 changes: 23 additions & 26 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "postcss-use",
"version": "2.3.0",
"version": "3.0.0",
"description": "Enable PostCSS plugins directly in your stylesheet.",
"main": "dist/index.js",
"files": [
Expand All @@ -13,8 +13,7 @@
"pretest": "eslint src/*.js src/__test__/*.js",
"prepublish": "del-cli dist && cross-env BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/",
"report": "nyc report --reporter=html",
"test": "nyc ava src/__tests__/*.js",
"test-012": "nyc ava src/__tests__/*.js"
"test": "nyc ava src/__tests__/*.js"
},
"keywords": [
"css",
Expand All @@ -23,26 +22,26 @@
],
"license": "MIT",
"devDependencies": {
"all-contributors-cli": "^3.0.4",
"autoprefixer": "^6.2.3",
"ava": "^0.17.0",
"babel-cli": "^6.5.1",
"babel-core": "^6.5.1",
"babel-plugin-add-module-exports": "^0.2.0",
"babel-preset-es2015-loose": "^7.0.0",
"babel-preset-stage-0": "^6.5.0",
"babel-register": "^6.9.0",
"coveralls": "^2.11.6",
"cross-env": "^2.0.0",
"del-cli": "^0.2.0",
"all-contributors-cli": "^4.10.1",
"autoprefixer": "^8.0.0",
"ava": "^0.25.0",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-eslint": "^8.2.1",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-preset-env": "^1.6.1",
"babel-register": "^6.26.0",
"coveralls": "^3.0.0",
"cross-env": "^5.1.3",
"del-cli": "^1.1.0",
"eslint": "^3.1.0",
"eslint-config-cssnano": "^3.1.2",
"eslint-plugin-babel": "^3.3.0",
"eslint-plugin-import": "^1.10.3",
"nyc": "^10.0.0",
"postcss-cssnext": "^2.6.0",
"postcss-discard-comments": "^2.0.3",
"postcss-discard-font-face": "^3.0.0"
"eslint-config-cssnano": "^3.1.3",
"eslint-plugin-babel": "^4.1.2",
"eslint-plugin-import": "^2.8.0",
"nyc": "^11.4.1",
"postcss-discard-comments": "^2.0.4",
"postcss-discard-font-face": "^3.0.0",
"postcss-nesting": "^4.2.1"
},
"homepage": "https://github.com/postcss/postcss-use",
"author": {
Expand All @@ -52,10 +51,8 @@
},
"repository": "postcss/postcss-use",
"dependencies": {
"balanced-match": "^0.4.1",
"lodash.isplainobject": "^4.0.6",
"postcss": "^5.0.21",
"resolve-from": "^2.0.0"
"postcss": "^6.0.17",
"resolve-from": "^4.0.0"
},
"ava": {
"require": "babel-register"
Expand Down

0 comments on commit 8cbc71a

Please sign in to comment.