Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

Commit 7af4c23

Browse files
authored
Support PostCSS 8 (#8)
1 parent 936585c commit 7af4c23

File tree

5 files changed

+44
-55
lines changed

5 files changed

+44
-55
lines changed

.rollup.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
1-
import pkg from './package.json'
1+
import babel from '@rollup/plugin-babel';
22

33
export default {
4-
...pkg.rollup,
5-
plugins: pkg.rollup.plugins.map(plugin => require(plugin)()),
4+
input: 'src/index.js',
5+
output: [
6+
{ file: 'dist/index.cjs.js', format: 'cjs', sourcemap: true, exports: 'default' },
7+
{ file: 'dist/index.esm.js', format: 'esm', sourcemap: true, exports: 'default' }
8+
],
9+
plugins: [
10+
babel({
11+
babelHelpers: 'bundled',
12+
presets: [
13+
['@babel/preset-env', {
14+
corejs: 3,
15+
loose: true,
16+
modules: false,
17+
targets: { node: 10 },
18+
useBuiltIns: 'entry'
19+
}]
20+
]
21+
}),
22+
],
623
onwarn(warning, warn) {
724
if (warning.code !== 'UNRESOLVED_IMPORT') warn(warning)
825
}

INSTALL.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,10 @@ instructions for:
1111
Add [PostCSS Lab Function] to your project:
1212

1313
```bash
14-
npm install postcss-lab-function --save-dev
14+
npm install postcss postcss-lab-function --save-dev
1515
```
1616

17-
Use [PostCSS Lab Function] to process your CSS:
18-
19-
```js
20-
const postcssLabFunction = require('postcss-lab-function');
21-
22-
postcssLabFunction.process(YOUR_CSS /*, processOptions, pluginOptions */);
23-
```
24-
25-
Or use it as a [PostCSS] plugin:
17+
Use it as a [PostCSS] plugin:
2618

2719
```js
2820
const postcss = require('postcss');

README.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,10 @@
2828
Add [PostCSS Lab Function] to your project:
2929

3030
```bash
31-
npm install postcss-lab-function --save-dev
31+
npm install postcss postcss-lab-function --save-dev
3232
```
3333

34-
Use [PostCSS Lab Function] to process your CSS:
35-
36-
```js
37-
const postcssLabFunction = require('postcss-lab-function');
38-
39-
postcssLabFunction.process(YOUR_CSS /*, processOptions, pluginOptions */);
40-
```
41-
42-
Or use it as a [PostCSS] plugin:
34+
Use it as a [PostCSS] plugin:
4335

4436
```js
4537
const postcss = require('postcss');

package.json

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,20 @@
2727
},
2828
"dependencies": {
2929
"@csstools/convert-colors": "^2.0.0",
30-
"postcss": "^7.0.27",
31-
"postcss-values-parser": "^3.2.0"
30+
"postcss-values-parser": "^4.0.0"
31+
},
32+
"peerDependencies": {
33+
"postcss": "^8.0.0"
3234
},
3335
"devDependencies": {
34-
"@babel/core": "^7.9.0",
35-
"@babel/preset-env": "^7.9.5",
36+
"@babel/core": "^7.11.6",
37+
"@babel/preset-env": "^7.11.5",
38+
"@rollup/plugin-babel": "^5.2.1",
3639
"babel-eslint": "^10.1.0",
37-
"eslint": "^6.8.0",
38-
"postcss-tape": "^5.0.2",
39-
"rollup": "^2.7.2",
40-
"rollup-plugin-babel": "^4.4.0"
40+
"eslint": "^7.10.0",
41+
"postcss": "^8.1.0",
42+
"postcss-tape": "^6.0.0",
43+
"rollup": "^2.28.2"
4144
},
4245
"babel": {
4346
"presets": [
@@ -57,22 +60,6 @@
5760
"extends": "eslint:recommended",
5861
"parser": "babel-eslint"
5962
},
60-
"rollup": {
61-
"input": "src/index.js",
62-
"plugins": [
63-
"rollup-plugin-babel"
64-
],
65-
"output": [
66-
{
67-
"file": "dist/index.cjs.js",
68-
"format": "cjs"
69-
},
70-
{
71-
"file": "dist/index.esm.js",
72-
"format": "esm"
73-
}
74-
]
75-
},
7663
"keywords": [
7764
"postcss",
7865
"css",

src/index.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
import postcss from 'postcss'
21
import onCSSDeclaration from './onCSSDeclaration'
32
import options from './options'
43

54
/** Transform lab() and lch() functions in CSS. */
6-
const postcssPlugin = postcss.plugin('postcss-lab-function', /** @type {PostCSSPluginInitializer} */ opts => {
5+
const postcssPlugin = /** @type {PostCSSPluginInitializer} */ opts => {
76
options.preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : false
87

9-
return root => {
10-
root.walkDecls(onCSSDeclaration)
8+
return {
9+
postcssPlugin: 'postcss-lab-function',
10+
Declaration: onCSSDeclaration,
1111
}
12-
})
12+
}
13+
14+
postcssPlugin.postcss = true
1315

1416
export default postcssPlugin
1517

16-
/** @typedef {import('postcss').Root} CSSRoot */
17-
/** @typedef {(root: CSSRoot) => void} PostCSSTransformCallback */
18-
/** @typedef {(opts: options) => PostCSSTransformCallback} PostCSSPluginInitializer */
18+
/** @typedef {import('postcss').Plugin} PostCSSPlugin */
19+
/** @typedef {(opts: options) => PostCSSPlugin} PostCSSPluginInitializer */

0 commit comments

Comments
 (0)