13
13
```
14
14
## Usage
15
15
16
- Plugins will be loaded directly from your projects *** package.json*** file.
17
- Install them as usual with ``` npm i -S ``` or ``` npm i -D ``` .
16
+ Plugins will be loaded directly from your projects *** package.json*** file or local installed plugins .
17
+ Install them as usual with ``` npm i -S ``` or ``` npm i -D ``` or ``` npm i ``` .
18
18
19
19
[ PostHTML Plugins] ( https://maltsev.github.io/posthtml-plugins/ )
20
20
@@ -24,6 +24,7 @@ After installing your plugins there a three ways to declare your plugin options.
24
24
- Set options in your *** package.json*** .
25
25
- Create a separated *** [ name] .[ ext] *** file, where *** [ name] *** is any name you like and *** [ ext] *** should be either ``` .js ``` or ``` .json ``` .
26
26
For an example of well formed options file see below.
27
+ - For plugins not having rules installed locally will be used default settings.
27
28
28
29
## Options
29
30
@@ -32,26 +33,26 @@ For an example of well formed options file see below.
32
33
``` json
33
34
{
34
35
"dependencies" : {
35
- "posthtml-bem" : " ^0.2.2" ,
36
- "posthtml-each" : " ^1.0.1" ,
37
- "posthtml-include" : " ^1.0.2"
36
+ "posthtml-bem" : " ^0.2.2" ,
37
+ "posthtml-each" : " ^1.0.1" ,
38
+ "posthtml-include" : " ^1.0.2"
38
39
},
39
40
"devDependencies" : {
40
- "posthtml-style-to-file" : " ^0.1.1"
41
+ "posthtml-style-to-file" : " ^0.1.1"
41
42
},
42
43
"posthtml" : {
43
- "bem" : {
44
- "elemPrefix" : " __" ,
45
- "modPrefix" : " -" ,
46
- "modDlmtr" : " --"
47
- },
48
- "include" : {
49
- "root" : " ./" ,
50
- "encoding" : " utf-8"
51
- },
52
- "styleToFile" : {
53
- "path" : " ./dist/style.css"
54
- }
44
+ "bem" : {
45
+ "elemPrefix" : " __" ,
46
+ "modPrefix" : " -" ,
47
+ "modDlmtr" : " --"
48
+ },
49
+ "include" : {
50
+ "root" : " ./" ,
51
+ "encoding" : " utf-8"
52
+ },
53
+ "styleToFile" : {
54
+ "path" : " ./dist/style.css"
55
+ }
55
56
}
56
57
}
57
58
```
@@ -61,36 +62,36 @@ For an example of well formed options file see below.
61
62
#### JS
62
63
``` js
63
64
module .exports = {
64
- bem: {
65
- elemPrefix: ' __' ,
66
- modPrefix: ' -' ,
67
- modDlmtr: ' --'
68
- },
69
- include: {
70
- root: ' ./' ,
71
- encoding: ' utf-8'
72
- },
73
- styleToFile: {
74
- path: ' ./dist/style.css'
75
- }
65
+ bem: {
66
+ elemPrefix: ' __' ,
67
+ modPrefix: ' -' ,
68
+ modDlmtr: ' --'
69
+ },
70
+ include: {
71
+ root: ' ./' ,
72
+ encoding: ' utf-8'
73
+ },
74
+ styleToFile: {
75
+ path: ' ./dist/style.css'
76
+ }
76
77
}
77
78
```
78
79
#### JSON
79
80
80
81
``` json
81
82
{
82
- "bem" : {
83
- "elemPrefix" : " __" ,
84
- "modPrefix" : " -" ,
85
- "modDlmtr" : " --"
86
- },
87
- "include" : {
88
- "root" : " ./" ,
89
- "encoding" : " utf-8"
90
- },
91
- "styleToFile" : {
92
- "path" : " ./dist/style.css"
93
- }
83
+ "bem" : {
84
+ "elemPrefix" : " __" ,
85
+ "modPrefix" : " -" ,
86
+ "modDlmtr" : " --"
87
+ },
88
+ "include" : {
89
+ "root" : " ./" ,
90
+ "encoding" : " utf-8"
91
+ },
92
+ "styleToFile" : {
93
+ "path" : " ./dist/style.css"
94
+ }
94
95
}
95
96
```
96
97
@@ -111,8 +112,8 @@ const plugins = require('posthtml-load-plugins')()
111
112
let html = fs .readFileSync (' ./index.html' , ' utf8' )
112
113
113
114
posthtml (plugins)
114
- .process (html)
115
- .then (result => console .log (result .html ))
115
+ .process (html)
116
+ .then (result => console .log (result .html ))
116
117
```
117
118
118
119
#### Options file (e.g posthtml.json)
@@ -128,9 +129,27 @@ const plugins = require('posthtml-load-plugins')('posthtml.(js|json)')
128
129
let html = fs .readFileSync (' ./index.html' , ' utf8' )
129
130
130
131
posthtml (plugins)
131
- .process (html)
132
- .then (result => console .log (result .html ))
132
+ .process (html)
133
+ .then (result => console .log (result .html ))
133
134
```
135
+
136
+ #### Extends options
137
+
138
+ ``` js
139
+ ' use strict'
140
+
141
+ const fs = require (' fs' )
142
+
143
+ const posthtml = require (' posthtml' )
144
+ const plugins = require (' posthtml-load-plugins' )(' posthtml.(js|json)' , {" posthtml-bem" : {elemPrefix: ' __' }})
145
+
146
+ let html = fs .readFileSync (' ./index.html' , ' utf8' )
147
+
148
+ posthtml (plugins)
149
+ .process (html)
150
+ .then (result => console .log (result .html ))
151
+ ```
152
+
134
153
## Contributors
135
154
136
155
[ ![ GitScrum] ( https://avatars.githubusercontent.com/u/2789192?s=130 )] ( https://github.com/GitScrum ) |
0 commit comments