Skip to content

PostCSS Global Data #841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/css-issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ body:
- PostCSS Focus Within
- PostCSS Font Variant
- PostCSS Gap Properties
- PostCSS Global Data
- PostCSS Gradients Interpolation Method
- PostCSS HWB Function
- PostCSS Image Set Function
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/plugin-issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ body:
- PostCSS Focus Within
- PostCSS Font Variant
- PostCSS Gap Properties
- PostCSS Global Data
- PostCSS Gradients Interpolation Method
- PostCSS HWB Function
- PostCSS Image Set Function
Expand Down
8 changes: 7 additions & 1 deletion .github/bin/generate-docs/readme.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ const template = await fsp.readFile(path.join('docs', './README.md'), 'utf8');
const corsTemplate = await fsp.readFile(path.join(path.dirname(fileURLToPath(import.meta.url)), './cors-template.md'), 'utf8');
const packageJSONInfo = JSON.parse(await fsp.readFile('./package.json', 'utf8'));

const exampleFilePaths = await fsp.readdir(path.join('test', 'examples'));
let exampleFilePaths = [];

try {
exampleFilePaths = await fsp.readdir(path.join('test', 'examples'));
} catch(error) {
// No examples
}

let readmeDoc = template.toString();

Expand Down
4 changes: 4 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@
- plugins/postcss-gap-properties/**
- experimental/postcss-gap-properties/**

"plugins/postcss-global-data":
- plugins/postcss-global-data/**
- experimental/postcss-global-data/**

"plugins/postcss-gradients-interpolation-method":
- plugins/postcss-gradients-interpolation-method/**
- experimental/postcss-gradients-interpolation-method/**
Expand Down
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions plugins/postcss-global-data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
package-lock.json
yarn.lock
*.result.css
*.result.css.map
*.result.html
1 change: 1 addition & 0 deletions plugins/postcss-global-data/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.8.0
17 changes: 17 additions & 0 deletions plugins/postcss-global-data/.tape.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { postcssTape } from '../../packages/postcss-tape/dist/index.mjs';
import plugin from '@csstools/postcss-global-data';
import postcssCustomMedia from 'postcss-custom-media';

postcssTape(plugin)({
basic: {
message: "supports basic usage",
plugins: [
plugin({
files: [
'./test/fixtures/fixture.css',
]
}),
postcssCustomMedia(),
],
},
});
5 changes: 5 additions & 0 deletions plugins/postcss-global-data/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changes to PostCSS global-data

### Unreleased (major)

- Initial version
235 changes: 235 additions & 0 deletions plugins/postcss-global-data/INSTALL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
# Installing PostCSS Global Data

[PostCSS Global Data] runs in all Node environments, with special instructions for:

- [Node](#node)
- [PostCSS CLI](#postcss-cli)
- [PostCSS Load Config](#postcss-load-config)
- [Webpack](#webpack)
- [Next.js](#nextjs)
- [Gulp](#gulp)
- [Grunt](#grunt)



## Node

Add [PostCSS Global Data] to your project:

```bash
npm install postcss @csstools/postcss-global-data --save-dev
```

Use it as a [PostCSS] plugin:

```js
// commonjs
const postcss = require('postcss');
const postcssGlobalData = require('@csstools/postcss-global-data');

postcss([
postcssGlobalData(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);
```

```js
// esm
import postcss from 'postcss';
import postcssGlobalData from '@csstools/postcss-global-data';

postcss([
postcssGlobalData(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);
```

## PostCSS CLI

Add [PostCSS CLI] to your project:

```bash
npm install postcss-cli @csstools/postcss-global-data --save-dev
```

Use [PostCSS Global Data] in your `postcss.config.js` configuration file:

```js
const postcssGlobalData = require('@csstools/postcss-global-data');

module.exports = {
plugins: [
postcssGlobalData(/* pluginOptions */)
]
}
```

## PostCSS Load Config

If your framework/CLI supports [`postcss-load-config`](https://github.com/postcss/postcss-load-config).

```bash
npm install @csstools/postcss-global-data --save-dev
```

`package.json`:

```json
{
"postcss": {
"plugins": {
"@csstools/postcss-global-data": {}
}
}
}
```

`.postcssrc.json`:

```json
{
"plugins": {
"@csstools/postcss-global-data": {}
}
}
```

_See the [README of `postcss-load-config`](https://github.com/postcss/postcss-load-config#usage) for more usage options._

## Webpack

_Webpack version 5_

Add [PostCSS Loader] to your project:

```bash
npm install postcss-loader @csstools/postcss-global-data --save-dev
```

Use [PostCSS Global Data] in your Webpack configuration:

```js
module.exports = {
module: {
rules: [
{
test: /\.css$/i,
use: [
"style-loader",
{
loader: "css-loader",
options: { importLoaders: 1 },
},
{
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: [
// Other plugins,
[
"@csstools/postcss-global-data",
{
// Options
},
],
],
},
},
},
],
},
],
},
};
```

## Next.js

Read the instructions on how to [customize the PostCSS configuration in Next.js](https://nextjs.org/docs/advanced-features/customizing-postcss-config)

```bash
npm install @csstools/postcss-global-data --save-dev
```

Use [PostCSS Global Data] in your `postcss.config.json` file:

```json
{
"plugins": [
"@csstools/postcss-global-data"
]
}
```

```json5
{
"plugins": [
[
"@csstools/postcss-global-data",
{
// Optionally add plugin options
}
]
]
}
```

## Gulp

Add [Gulp PostCSS] to your project:

```bash
npm install gulp-postcss @csstools/postcss-global-data --save-dev
```

Use [PostCSS Global Data] in your Gulpfile:

```js
const postcss = require('gulp-postcss');
const postcssGlobalData = require('@csstools/postcss-global-data');

gulp.task('css', function () {
var plugins = [
postcssGlobalData(/* pluginOptions */)
];

return gulp.src('./src/*.css')
.pipe(postcss(plugins))
.pipe(gulp.dest('.'));
});
```

## Grunt

Add [Grunt PostCSS] to your project:

```bash
npm install grunt-postcss @csstools/postcss-global-data --save-dev
```

Use [PostCSS Global Data] in your Gruntfile:

```js
const postcssGlobalData = require('@csstools/postcss-global-data');

grunt.loadNpmTasks('grunt-postcss');

grunt.initConfig({
postcss: {
options: {
processors: [
postcssGlobalData(/* pluginOptions */)
]
},
dist: {
src: '*.css'
}
}
});
```

[Gulp PostCSS]: https://github.com/postcss/gulp-postcss
[Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
[PostCSS]: https://github.com/postcss/postcss
[PostCSS CLI]: https://github.com/postcss/postcss-cli
[PostCSS Loader]: https://github.com/postcss/postcss-loader
[PostCSS Global Data]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-global-data
[Next.js]: https://nextjs.org
Loading