2 Star 0 Fork 0

mirrors_posthtml/posthtml-load-plugins

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
9年前
Loading...
README
MIT

npm version Dependencies Build Status Coverage Status XO Code Style

Autoload Plugins for PostHTML

Install

(sudo) npm i -D posthtml-load-plugins

Usage

Plugins will be loaded directly from your projects package.json file or local installed plugins.
Install them as usual with npm i -S or npm i -D or npm i.

PostHTML Plugins

After installing your plugins there a three ways to declare your plugin options.

  • Set options directly as arguments.
  • Set options in your package.json.
  • Create a separated [name].[ext] file, where [name] is any name you like and [ext] should be either .js or .json. For an example of well formed options file see below.
  • For plugins not having rules installed locally will be used default settings.
  • Pretty reporting about not installed plugins.

Options

package.json

{
    "dependencies": {
        "posthtml-bem": "^0.2.2",
        "posthtml-each": "^1.0.1",
        "posthtml-include": "^1.0.2"
},
    "devDependencies": {
        "posthtml-style-to-file": "^0.1.1"
},
    "posthtml": {
        "bem": {
            "elemPrefix": "__",
            "modPrefix": "-",
            "modDlmtr": "--"
        },
        "include": {
            "root": "./",
            "encoding": "utf-8"
        },
        "styleToFile": {
            "path": "./dist/style.css"
        }
    }
}

[name].[ext]

JS

module.exports = {
    bem: {
        elemPrefix: '__',
        modPrefix: '-',
        modDlmtr: '--'
    },
    include: {
        root: './',
        encoding: 'utf-8'
    },
    styleToFile: {
        path: './dist/style.css'
    }
}

or

module.exports = [
    {
        bem: {
            elemPrefix: '__',
            modPrefix: '-',
            modDlmtr: '--'
        },
        include: {
            root: './',
            encoding: 'utf-8'
        }
    }, {
        styleToFile: {
            path: './dist/style.css'
        }
    }
]

JSON

{
    "bem": {
        "elemPrefix": "__",
        "modPrefix": "-",
        "modDlmtr": "--"
    },
    "include": {
        "root": "./",
        "encoding": "utf-8"
    },
    "styleToFile": {
        "path": "./dist/style.css"
    }
}

Usage

For general usage and build process integration see PostHTML Docs

Examples using Node API

Default

const fs = require('fs');

const posthtml = require('posthtml');
const plugins = require('posthtml-load-plugins');

let html = fs.readFileSync('./index.html', 'utf8');

posthtml(plugins([object|array[objects]|file] /* options */, [object|array[objects]|file] /* extends */))
    .process(html)
    .then(result => console.log(result.html));

Options file (e.g posthtml.json)

const fs = require('fs');

const posthtml = require('posthtml');
const plugins = require('posthtml-load-plugins')('posthtml.(js|json)');

let html = fs.readFileSync('./index.html', 'utf8');

posthtml(plugins)
    .process(html)
    .then(result => console.log(result.html));

Extends options

const fs = require('fs');

const posthtml = require('posthtml');
const plugins = require('posthtml-load-plugins')('posthtml.(js|json)', {"posthtml-bem": {elemPrefix: '__'}});

let html = fs.readFileSync('./index.html', 'utf8');

posthtml(plugins)
    .process(html)
    .then(result => console.log(result.html));

Use with posthtml-standard-config

const fs = require('fs');

const posthtml = require('posthtml');
const standardConfig = require('posthtml-standard-config');
const plugins = require('posthtml-load-plugins')(standardConfig);

let html = fs.readFileSync('./index.html', 'utf8');

posthtml(plugins)
    .process(html)
    .then(result => console.log(result.html));

Contributors

GitScrum
Ivan Demidov

License

MIT

The MIT License (MIT) Copyright (c) 2016 Michael Ciniawsky Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

Autoload Plugins for PostHTML 展开 收起
README
MIT
取消

发行版

暂无发行版

贡献者 (3)

全部

近期动态

接近5年前创建了仓库
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_posthtml/posthtml-load-plugins.git
git@gitee.com:mirrors_posthtml/posthtml-load-plugins.git
mirrors_posthtml
posthtml-load-plugins
posthtml-load-plugins
master

搜索帮助