1
- # html loader for webpack
1
+ [ ![ npm] [ npm ]] [ npm-url ]
2
+ [ ![ deps] [ deps ]] [ deps-url ]
3
+ [ ![ test] [ test ]] [ test-url ]
4
+ [ ![ coverage] [ cover ]] [ cover-url ]
5
+ [ ![ chat] [ chat ]] [ chat-url ]
6
+
7
+ <div align =" center " >
8
+ <img width="200" height="200"
9
+ src="https://worldvectorlogo.com/logos/html5.svg">
10
+ <a href =" https://github.com/webpack/webpack " >
11
+ <img width="200" height="200" vspace="" hspace="25"
12
+ src="https://worldvectorlogo.com/logos/webpack.svg">
13
+ </a >
14
+ <h1 >HTML Loader</h1 >
15
+ <p >Exports HTML as string. HTML is minimized when the compiler demands.<p >
16
+ </div >
17
+
18
+ <h2 align =" center " >Install</h2 >
19
+
20
+ ``` bash
21
+ npm i -D html-loader
22
+ ```
2
23
3
- Exports HTML as string. HTML is minimized when the compiler demands.
24
+ < h2 align = " center " >Usage</ h2 >
4
25
5
- By default every local ` <img src="image.png"> ` is required (` require(" ./image.png" ) ` ). You may need to specify loaders for images in your configuration (recommended ` file-loader ` or ` url-loader ` ).
26
+ By default every local ` <img src="image.png"> ` is required (` require(' ./image.png' ) ` ). You may need to specify loaders for images in your configuration (recommended ` file-loader ` or ` url-loader ` ).
6
27
7
28
You can specify which tag-attribute combination should be processed by this loader via the query parameter ` attrs ` . Pass an array or a space-separated list of ` <tag>:<attribute> ` combinations. (Default: ` attrs=img:src ` )
8
29
9
30
To completely disable tag-attribute processing (for instance, if you're handling image loading on the client side) you can pass in ` attrs=false ` .
10
31
11
- ## Usage
12
-
13
- [ Documentation: Using loaders] ( http://webpack.github.io/docs/using-loaders.html )
14
-
15
- ## Examples
32
+ <h2 align =" center " >Examples</h2 >
16
33
17
34
With this configuration:
18
35
19
- ``` javascript
36
+ ``` js
20
37
{
21
- module: { loaders: [
22
- { test: / \. jpg$ / , loader: " file-loader" },
23
- { test: / \. png$ / , loader: " url-loader?mimetype=image/png" }
24
- ]},
38
+ module: {
39
+ loaders: [
40
+ { test: / \. jpg$ / , loader: " file-loader" },
41
+ { test: / \. png$ / , loader: " url-loader?mimetype=image/png" }
42
+ ]
43
+ },
25
44
output: {
26
45
publicPath: " http://cdn.example.com/[hash]/"
27
46
}
28
47
}
29
48
```
30
49
31
50
``` html
32
- <!-- fileA .html -->
33
- <img src =" image.jpg " data-src =" image2x.png" >
51
+ <!-- file .html -->
52
+ <img src =" image.png " data-src =" image2x.png" >
34
53
```
35
54
36
- ``` javascript
37
- require (" html!./fileA.html" );
38
- // => '<img src="http://cdn.example.com/49e...ba9f/a9f...92ca.jpg" data-src="image2x.png" >'
55
+ ``` js
56
+ require (" html!./file.html" );
39
57
58
+ // => '<img src="http://cdn.example.com/49eba9f/a992ca.jpg"
59
+ // data-src="image2x.png">'
60
+ ```
61
+
62
+ ``` js
40
63
require (" html?attrs=img:data-src!./file.html" );
41
- // => '<img src="image.png" data-src="data:image/png;base64,..." >'
42
64
65
+ // => '<img src="image.png" data-src="data:image/png;base64,..." >'
66
+ ```
67
+
68
+ ``` js
43
69
require (" html?attrs=img:src img:data-src!./file.html" );
44
70
require (" html?attrs[]=img:src&attrs[]=img:data-src!./file.html" );
45
- // => '<img src="http://cdn.example.com/49e...ba9f/a9f...92ca.jpg" data-src="data:image/png;base64,..." >'
46
71
72
+ // => '<img src="http://cdn.example.com/49eba9f/a992ca.png"
73
+ // data-src="data:image/png;base64,..." >'
74
+ ```
75
+
76
+ ``` js
47
77
require (" html?-attrs!./file.html" );
78
+
48
79
// => '<img src="image.jpg" data-src="image2x.png" >'
80
+ ```
49
81
50
- // / minimized by running `webpack --optimize-minimize`
51
- // => '<img src=http://cdn.example.com/49e...ba9f/a9f...92ca.jpg data-src=data:image/png;base64,...>'
82
+ minimized by running ` webpack --optimize-minimize `
52
83
84
+ ``` html
85
+ '<img src =http://cdn.example.com/49eba9f/a9f92ca.jpg
86
+ data-src =data:image/png;base64,... >'
53
87
```
54
88
55
- ## 'Root-relative' urls
89
+ ### 'Root-relative' URLs
56
90
57
91
For urls that start with a ` / ` , the default behavior is to not translate them.
58
92
If a ` root ` query parameter is set, however, it will be prepended to the url
59
93
and then translated.
60
94
61
- With the same configuration above:
95
+ With the same configuration as above:
96
+
62
97
``` html
63
- <!-- fileB .html -->
98
+ <!-- file .html -->
64
99
<img src =" /image.jpg" >
65
100
```
66
101
67
- ``` javascript
102
+ ``` js
103
+ require (" html!./file.html" );
68
104
69
- require (" html!./fileB.html" );
70
105
// => '<img src="/image.jpg">'
106
+ ```
71
107
72
- require ( " html?root=.!./fileB.html " );
73
- // => '<img src="http://cdn.example.com/49e...ba9f/a9f...92ca.jpg">'
108
+ ``` js
109
+ require ( " html?root=.!./file.html " );
74
110
111
+ // => '<img src="http://cdn.example.com/49eba9f/a992ca.jpg">'
75
112
```
76
113
77
- ## Interpolation
114
+ ### Interpolation
78
115
79
116
You can use ` interpolate ` flag to enable interpolation syntax for ES6 template strings, like so:
80
117
81
- ```
118
+ ``` js
82
119
require (" html?interpolate!./file.html" );
83
120
```
84
121
85
- ```
86
- <img src="${require(`./images/gallery.png`)}" />
87
- <div>${require('./partials/gallery.html')}</div>
122
+ ``` html
123
+ <img src =" ${require(`./images/gallery.png`)}" >
124
+
125
+ <div >${require('./components/gallery.html')}</div >
88
126
```
89
127
90
- ## Advanced options
128
+ ### Advanced options
91
129
92
130
If you need to pass [ more advanced options] ( https://github.com/webpack/html-loader/pull/46 ) , especially those which cannot be stringified, you can also define an ` htmlLoader ` -property on your ` webpack.config.js ` :
93
131
94
- ``` javascript
95
- var path = require (' path' );
96
- ...
132
+ ``` js
133
+ var path = require (' path' )
134
+
97
135
module .exports = {
98
136
...
99
137
module: {
@@ -114,7 +152,7 @@ module.exports = {
114
152
115
153
If you need to define two different loader configs, you can also change the config's property name via ` html?config=otherHtmlLoaderConfig ` :
116
154
117
- ``` javascript
155
+ ``` js
118
156
module .exports = {
119
157
...
120
158
module: {
@@ -131,6 +169,92 @@ module.exports = {
131
169
};
132
170
```
133
171
134
- ## License
135
-
136
- MIT (http://www.opensource.org/licenses/mit-license.php )
172
+ <h2 align =" center " >Maintainers</h2 >
173
+
174
+ <table >
175
+ <tbody >
176
+ <tr>
177
+ <td align="center">
178
+ <img width="150 height="150"
179
+ src="https://avatars.githubusercontent.com/u/18315?v=3">
180
+ <a href="https://github.com/hemanth">Hermanth</a>
181
+ </td>
182
+ <td align="center">
183
+ <img width="150 height="150"
184
+ src="https://avatars.githubusercontent.com/u/8420490?v=3">
185
+ <a href="https://github.com/d3viant0ne">Joshua Wiens</a>
186
+ </td>
187
+ <td align="center">
188
+ <img width="150" height="150" src="https://avatars.githubusercontent.com/u/5419992?v=3">
189
+ <a href="https://github.com/michael-ciniawsky">Michael Ciniawsky</a>
190
+ </td>
191
+ <td align="center">
192
+ <img width="150" height="150"
193
+ src="https://avatars.githubusercontent.com/u/6542274?v=3">
194
+ <a href="https://github.com/imvetri">Imvetri</a>
195
+ </td>
196
+ <tr>
197
+ <tr>
198
+ <td align="center">
199
+ <img width="150" height="150"
200
+ src="https://avatars.githubusercontent.com/u/1520965?v=3">
201
+ <a href="https://github.com/andreicek">Andrei Crnković</a>
202
+ </td>
203
+ <td align="center">
204
+ <img width="150" height="150"
205
+ src="https://avatars.githubusercontent.com/u/3367801?v=3">
206
+ <a href="https://github.com/abouthiroppy">Yuta Hiroto</a>
207
+ </td>
208
+ <td align="center">
209
+ <img width="150" height="150" src="https://avatars.githubusercontent.com/u/80044?v=3">
210
+ <a href="https://github.com/petrunov">Vesselin Petrunov</a>
211
+ </td>
212
+ <td align="center">
213
+ <img width="150" height="150"
214
+ src="https://avatars.githubusercontent.com/u/973543?v=3">
215
+ <a href="https://github.com/gajus">Gajus Kuizinas</a>
216
+ </td>
217
+ <tr>
218
+ <tbody >
219
+ </table >
220
+
221
+ <h2 align =" center " >LICENSE</h2 >
222
+
223
+ > MIT
224
+
225
+ > http://www.opensource.org/licenses/mit-license.php
226
+
227
+ > Copyright (c) 2016 Tobias Koppers @sokra
228
+
229
+ > Permission is hereby granted, free of charge, to any person obtaining a copy
230
+ of this software and associated documentation files (the "Software"), to deal
231
+ in the Software without restriction, including without limitation the rights
232
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
233
+ copies of the Software, and to permit persons to whom the Software is
234
+ furnished to do so, subject to the following conditions:
235
+
236
+ > The above copyright notice and this permission notice shall be included in all
237
+ copies or substantial portions of the Software.
238
+
239
+ > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
240
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
241
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
242
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
243
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
244
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
245
+ SOFTWARE.
246
+
247
+ [ npm ] : https://img.shields.io/npm/v/html-loader.svg
248
+ [ npm-url ] : https://npmjs.com/package/html-loader
249
+
250
+ [ deps ] : https://david-dm.org/webpack/html-loader.svg
251
+ [ deps-url ] : https://david-dm.org/webpack/html-loader
252
+
253
+ [ chat ] : https://img.shields.io/badge/gitter-webpack%2Fwebpack-brightgreen.svg
254
+ [ chat-url ] : https://gitter.im/webpack/webpack
255
+
256
+ [ test ] : http://img.shields.io/travis/webpack/html-loader.svg
257
+ [ test-url ] : https://travis-ci.org/webpack/html-loader
258
+
259
+ [ cover ] : https://coveralls.io/repos/github/webpack/html-loader/badge.svg?branch=master
260
+ [ cover-url ] : https://coveralls.io/github/webpack/html-loader?branch=master
0 commit comments