postcss-global-import-once

3.0.1 • Public • Published

postcss-global-import-once

Build Status

PostCSS plugin to set import statements once globally.

This plugin does not inline imports. For that functionality, use postcss-import after this plugin.

Install

npm install postcss postcss-global-import-once --save

Usage

Given following configuration:

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

@import url('archie.css');
@import url('sophie.css');
@import url('cooper.css');

body {
	color: red;
}

input/page.css

@import url('archie.css');
@import url('sophie.css');
@import url('cooper.css');

body {
	color: red;
}

Will be treated as:

input/index.css

@import url('archie.css');
@import url('sophie.css');
@import url('cooper.css');

body {
	color: red;
}

input/page.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 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ć

Package Sidebar

Install

npm i postcss-global-import-once

Weekly Downloads

4

Version

3.0.1

License

MIT

Unpacked Size

15.9 kB

Total Files

8

Last publish

Collaborators

  • niksy