Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/niksy/postcss-global-import-once
PostCSS plugin to set import statements once globally.
https://github.com/niksy/postcss-global-import-once
Last synced: about 2 months ago
JSON representation
PostCSS plugin to set import statements once globally.
- Host: GitHub
- URL: https://github.com/niksy/postcss-global-import-once
- Owner: niksy
- License: mit
- Created: 2016-11-13T10:52:41.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2020-10-21T07:39:46.000Z (about 4 years ago)
- Last Synced: 2024-10-18T04:05:19.997Z (2 months ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# postcss-global-import-once
[![Build Status][ci-img]][ci]
PostCSS plugin to set import statements once globally.
This plugin does not inline imports. For that functionality, use
[postcss-import][postcss-import] after this plugin.## Install
```sh
npm install postcss postcss-global-import-once --save
```## Usage
Given following configuration:
```js
import postcss from 'postcss';
import globalAtImportOnce from 'postcss-global-import-once';
import { promises as fs } from 'fs';(async () => {
const results = await Promise.all(
['./input/index.css', './input/page.css'].map(async (file) => {
const style = await fs.readFile(file, 'utf8');return postcss([
globalAtImportOnce([
{
file: '**/index.css',
imports: ['archie.css', 'cooper.css']
}
])
]).process(style, {
from: file
});
})
);// …
})();
```Following input styles:
**`input/index.css`**
```css
@import url('archie.css');
@import url('sophie.css');
@import url('cooper.css');body {
color: red;
}
```**`input/page.css`**
```css
@import url('archie.css');
@import url('sophie.css');
@import url('cooper.css');body {
color: red;
}
```Will be treated as:
**`input/index.css`**
```css
@import url('archie.css');
@import url('sophie.css');
@import url('cooper.css');body {
color: red;
}
```**`input/page.css`**
```css
@import url('sophie.css');body {
color: red;
}
```## API
### globalAtImportOnce(options)
PostCSS `from` option should be defined for this plugin to work properly.
#### options
Type: `Object[]`
Array of definitions (objects) for global imports.
Each object definitions contains following properties:
#### file
Type: `String`
Name of the file or [minimatch][minimatch] expression which is considered as
global entry point.#### imports
Type: `Array`
List of imports as strings which are considered to be global imports. Only exact
names defined inside files are considered, so relative filepaths which map to
certain absolute filepaths are treated as different filepaths.## License
MIT © [Ivan Nikolić](http://ivannikolic.com)
[ci]: https://travis-ci.com/niksy/postcss-global-import-once
[ci-img]: https://travis-ci.com/niksy/postcss-global-import-once.svg?branch=master
[postcss-import]: https://github.com/postcss/postcss-import
[minimatch]: https://github.com/isaacs/minimatch