Skip to content

Latest commit

 

History

History
179 lines (144 loc) · 6.63 KB

readme.md

File metadata and controls

179 lines (144 loc) · 6.63 KB

post-load-plugins

Automatically detects processor and creates a configuration for used the plugins.

Travis Build StatusAppVeyor Build Statusnodenpm versionDependency StatusXO code styleCoveralls status

npm downloadsnpmPackage Quality

Why?

Automatically detects the running environment on the basis of which creates the configuration for plugins using post-config used in the process and sorts the execution order of plugins using post-sequence.

post-config - Automatically detect all plugins installed and create a configuration for them from the description in package.json used in the process.

post-sequence - Generates the correct sequence of execution of plug-ins for the executable

At the moment the tested processors:

Will inform you if the plugin has not been installed:

Install

$ npm install post-load-plugins 

Note: This project is compatible with node v4+

Usage

  1. Install processor PostHTML or PostCSS or both and post-load-plugins
$ npm install postcss posthtml post-load-plugins 
  1. Install plugins for your processor
$ npm install autoprefixer postcss-at-rules-variables postcss-csso posthtml-bem posthtml-beautify
  1. Optional Create configuration for plugins is different from the default in package.json.

For plugins not having configuration installed locally will be used default settings.

"postcss":{
  "plugins": {
    "autoprefixer": {
      "browsers": ["last 2 versions"]
    },
    "at-rules-variables": {
      "atRule": ["@media"]
    }
  }
},
"posthtml": {
  "bem": {
    "elemPrefix": "__",
    "modPrefix": "--",
    "modDlmtr": "-"
  }
}

Attention, it is recommended to use notation as above for postcss postcss: { plugins: { ... } }, but both types are supported notation posthtml: { bem: { ... }, plugins: { beautify: { ... } } }.

The names of the plugins it is recommended to use no name of the processor as described above for postcss, but supported the full name of the plugin, the plugin name without the process in kebab at-rules-variables and camel case atRulesVariables.

Example

using PostCSS

package.json

"name": "my-post-project",
"devDependencies": {
    "autoprefixer": "^6.5.4",
    "postcss": "^5.2.6",
    "postcss-csso": "^1.1.2"
},
"postcss":{
  "plugins": {
    "autoprefixer": {
      "browsers": ["last 2 versions"]
    }
  }
}

index.js

import postcss from 'postcss';
import postLoadPlugins from 'post-load-plugins';

postcss(postLoadPlugins()).process('.test { display: flex; color: #ff0000;} @charset "utf-8";');
// Result => .test{display:-ms-flexbox;display:flex;color:red}

Will apply autoprefixer with option described in the configuration "browsers": ["last 2 versions"] and postcss-csso with default settings

--

using PostHTML

package.json

"name": "my-post-project",
"devDependencies": {
    "posthtml": "^0.9.0",
    "posthtml-bem": "^0.2.2",
    "posthtml-beautify": "0.1.0"
},
"posthtml": {
  "bem": {
    "elemPrefix": "__",
    "modPrefix": "--",
    "modDlmtr": "-"
  }
}

index.js

import posthtml from 'posthtml';
import postLoadPlugins from 'post-load-plugins';

const html = `
  <div block="content">
    <h1 elem="title">Title</h1>
    <p elem="text" mods="red">Text</p>
  </div>
`;

posthtml(postLoadPlugins()).process(html);
//  Result =>
//  <div class="content">
//    <h1 class="content__title">Title</h1>
//
//    <p class="content__text content__text--red">Text</p>
//  </div>

Will apply posthtml-bem with option described in the configuration "elemPrefix": "__","modPrefix": "--","modDlmtr": "-" and posthtml-beautify with default settings

Options

extends

Type: Array
Default: []
Description: May contain an Object with properties or path to config for the expansion

extend.config.json

"bem": {
  "modPrefix": "---"
}

Will automatically try to determine if you do not specify a process name in the package name or the package does not reside in the property matching process

index.js

import posthtml from 'posthtml';
import postLoadPlugins from 'post-load-plugins';

const html = `
  <div block="content">
    <h1 elem="title">Title</h1>
    <p elem="text" mods="red">Text</p>
  </div>
`;

posthtml(postLoadPlugins({extends: ['path/to/file/extend.config.json']})).process(html);

//  Result =>
//  <div class="content">
//    <h1 class="content__title">Title</h1>
//
//    <p class="content__text content__text---red">Text</p>
//  </div>

Expand the current configuration for posthtml plugins bem