Package detail

postcss-map

pascalduez6kUnlicense0.11.0

PostCSS plugin enabling configuration maps

css, map, postcss, postcss-plugin

readme

postcss-map

npm version Build Status Coverage Status

PostCSS plugin enabling configuration maps.

Installation

npm install postcss-map --save-dev

or

yarn add postcss-map --save-dev

Usage

const fs = require('fs');
const postcss = require('postcss');
const map = require('postcss-map');

let input = fs.readFileSync('input.css', 'utf8');

let opts = {
  basePath: 'css',
  maps: ['example.yml', 'breakpoints.yml', 'fonts.yml'],
};

postcss()
  .use(map(opts))
  .process(input)
  .then(result => {
    fs.writeFileSync('output.css', result.css);
  });

Example usage from declaration values

map:

# example.yml
foo:
  bar:
    baz: 'yeah!'

input:

.baz {
  content: map(example, foo, bar, baz);
}

output:

.baz {
  content: 'yeah!';
}

Example usage from at-rules parameters

map:

# breakpoints.yml
small: 320px
medium: 321px
large: 800px

input:

@media (min-width: map(breakpoints, medium)) {
  .test {
    width: 100%;
  }
}

output:

@media (min-width: 321px) {
  .test {
    width: 100%;
  }
}

Example from declaration blocks

map:

# fonts.yml
regular:
  font-family: "'Spinnaker Regular', sans-serif"
  font-weight: 'normal'
  font-feature-settings: "'onum', 'kern', 'liga', 'dlig', 'clig'"
  font-kerning: 'normal'
bold:
  font-family: "'Spinnaker Bold', sans-serif"
  font-weight: 'normal'
  font-feature-settings: "'onum', 'kern', 'liga', 'dlig', 'clig'"
  font-kerning: 'normal'

input:

.whatever {
  @map fonts regular;
}

output:

.whatever {
  font-family: 'Spinnaker Bold', sans-serif;
  font-weight: normal;
  font-feature-settings: 'onum', 'kern', 'liga', 'dlig', 'clig';
  font-kerning: normal;
}

Example usage with literal objects

const fs = require('fs');
const postcss = require('postcss');
const map = require('postcss-map');

let input = fs.readFileSync('input.css', 'utf8');

let opts = {
  basePath: 'css',
  maps: [
    {
      dummy: {
        one: 1,
        two: 2,
      },
    },
    'example.yml',
    'breakpoints.yml',
    'fonts.yml'
  }]
};

postcss()
  .use(map(opts))
  .process(input)
  .then(result => {
    fs.writeFileSync('output.css', result.css);
  });

input:

.whatever {
  content: map(dummy, one);
}

.baz {
  content: map(example, foo, bar, baz);
}

output:

.whatever {
  content: 1;
}

.baz {
  content: 'yeah!';
}

Example usage with literal objects and short syntax

const fs = require('fs');
const postcss = require('postcss');
const map = require('postcss-map');

let input = fs.readFileSync('input.css', 'utf8');

let opts = {
  maps: [
    {
      one: 1,
      two: 2,
    },
  ],
};

postcss()
  .use(map(opts))
  .process(input)
  .then(result => {
    fs.writeFileSync('output.css', result.css);
  });

input:

.whatever {
  content: map(one);
}

output:

.whatever {
  content: 1;
}

Options

basePath

type: String
default: process.cwd
Base path to retrieve maps from.

maps

type: Array
default: []
An array representing maps files to load and parse. Map files can either be in YAML or JSON format.
You can also pass literal objects directly into the Array.

defaultMap (short syntax)

type: string
default: config

A shorter syntax is also available, so you don't have to type the map name on each call. To enable it you need to either have a map called config or only one map in your settings.

let opts = {
  basePath: 'css',
  maps: ['foo.yml']
  // OR
  maps: ['config.yml', 'breakpoints.yml']
};

map:

# config.yml
foo: 'foo value'

input:

.short {
  content: map(foo);
}

output:

.short {
  content: 'foo value';
}

Context

Used in conjunction with postcss-plugin-context you can benefit from contextualized maps and leverage the short syntax.

@context brandColors {
  h1 {
    color: map(primary);
  }
}

Credits

Licence

postcss-map is unlicensed.

changelog

postcss-map change log

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

Unreleased

[0.11.0] - 2018-12-01

Added

  • Added ability to recursively resolve map values. (#113)

0.10.0 - 2018-08-12

Changed

  • Upgrade PostCSS to version 7. Breaking Removes support for Node.js versions lower than 6.

0.9.0 - 2017-05-07

Changed

  • PostCSS 6 upgrade.

0.8.0 - 2015-12-26

Added

  • Add a defaultMap option as well as a default config map. (#10)

0.7.2 - 2015-10-29

Fixed

  • Add filename to yaml parser for more informative error message.
  • Fix exceptions in promise.

0.7.1 - 2015-10-25

Fixed

  • Update Readme examples to use PostCSS async API.

0.7.0 - 2015-10-24

Changed

  • postcss-map is now fully async. (#17)
  • Reduced the number of AST loops.

0.6.0 - 2015-08-28

Changed

  • Prevent duplicate Parser initialization.

Added

  • Allow literal objects as map. (#15)

0.5.0 - 2015-08-27

Changed

  • Upgrade to PostCSS 5.
  • Several development process updates.

0.4.1 - 2015-05-02

Changed

  • Use standard package keyword. (#319)

0.4.0 - 2015-04-26

Added

  • Add a new "short" syntax. (#9)

0.3.0 - 2015-04-09

Changed

  • Allow multiple map fn calls from atRules. (#8)

0.2.0 - 2015-04-08

Changed

  • Use latest PostCSS 4.1.* plugin API.
  • Upgrade to Babel 5.0.

0.1.0 - 2015-03-06

  • Initial release.