1.0.0 • Published 3 years ago

postcss-icss-parser v1.0.0

Weekly downloads
6
License
MIT
Repository
-
Last release
3 years ago

postcss-icss-parser

A PostCSS plugin for parsing import/export statements out of CSS that follows the ICSS specification, eg. for CSS Modules.

This code was adapted from css-loader and modified to work as a stand-alone plugin.

This documentation is rudimentary and will probably be improved at some point. Feel free to open an issue if something is unclear!

License

This module is derived from: css-loader (https://github.com/webpack-contrib/css-loader)
	(c) JS Foundation and other contributors

Modifications by:
	(c) 2019, Sven Slootweg <admin@cryto.net>

Licensed under:
	MIT (https://opensource.org/licenses/MIT)

API

Exports a plugin that is compatible with PostCSS 8.

Takes the following options upon initialization:

  • keyReplacer: A function({ localKey, remoteKey, index, url }) that is expected to return the new, mangled name for a given imported identifier. - url: The path or URL that is being imported from. - localKey: The local name that it is imported under in the file. - remoteKey: The identifier name in the original file that is being imported from. - index: A number that increments for each processed import. Global across the entire AST pass.
  • autoExportImports: Optional. When set to true, the local key of every imported identifier is also automatically considered to be re-exported from the file, even if no explicit export statement exists for it.

When applied, it will extract import/export statements from the code, exposing them as the following types of messages (from plugin postcss-icss-parser):

  • icss-import: an import statement. - url, localKey, remoteKey, index: Same as for the keyReplacer option above. - newKey: The new key that was generated by the keyReplacer.
  • icss-export: an export statement. - name: The key being exported. - value: The value that this key holds.