Creates a configuration
For use in processors such as posthtml, postcss, reshape or for plug-ins. Automatically finds all the modules and tries to match them with the executable processes.
$ npm install post-config
Note: This project is compatible with node v4+
package.json
"name": "my-post-project",
"devDependencies": {
"posthtml": "^6.5.4",
"posthtml-spaceless": "^6.5.4",
"posthtml-custom-elements": "^5.2.6"
},
"posthtml":{
"sync": false,
"posthtml-custom-elements": {
"defaultTag": "span"
}
}
index.js
import posthtml from 'posthtml';
import postConfig from 'post-config';
const options = postConfig({namespace: ['posthtml']});
/*
Return configuration object for posthtml processor.
{
sync: false,
plugins: [
'posthtml-spaceless',
['posthtml-custom-elements', {
defaultTag: 'span'
}]
]
}
*/
const plugins = options.plugins.map(module => {
let config = {};
if (Array.isArray(module)) {
[module, config] = module;
}
return require(module)(config);
});
const html = `
<component>
<h1>Super Title</h1>
<text tag="p">Awesome Text</text>
<spaceless>
<ul>
<li class="box-inline col-6">Link</li>
<li class="box-inline col-6">Link</li>
</ul>
</spaceless>
</component>
`;
posthtml(plugins)
.process(html, options)
.then(result => console.log(result.html));
/*
Return result
<article class="component">
<h1>Super Title</h1>
<p>Awesome Text</p>
<ul><li class="box-inline col-6">Link</li><li class="box-inline col-6">Link</li></ul>
</article>
*/
Type: String
Default: "./"
Description: Directory to find package.json
Type: String|Boolean
Default: node_modules
Description: Directory to find modules relatively root
dirictory. Set falsely is not necessary to look for modules in node_modules
Type: Array
Default: []
Description: Makes a search and a resulting configuration object for specified namespaces
Type: Object
Default: {}
Description: Can extend configurations
-
Type:
Object
Default:{}
Description: Inherits, supplements, and extends the resulting configuration object -
Type:
Array|String
Default:[]
Description: Expands the list of namespace for better matching of modules -
Type:
Array
Default:[]
Description: Inherits, supplements, and extends the resulting configuration object -
Type:
Object
Default: white-list.js
Description: Expands the list of module to namespace relationships -
Type:
Array
Default: black-list.js
Description: Modules necessary to ignore when building the final configuration object