UNPKG

2.76 kBMarkdownView Raw
1# html loader for webpack
2
3Exports HTML as string. HTML is minimized when the compiler demands.
4
5By 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
7You 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
9To completely disable tag-attribute processing (for instance, if you're handling image loading on the client side) you can pass in `attrs=false`.
10
11## Usage
12
13[Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html)
14
15## Examples
16
17With this configuration:
18
19``` javascript
20{
21 module: { loaders: [
22 { test: "\.jpg$", loader: "file-loader" },
23 { test: "\.png$", loader: "url-loader?mimetype=image/png" }
24 ]},
25 output: {
26 publicPath: "http://cdn.example.com/[hash]/"
27 }
28}
29```
30
31``` html
32<!-- fileA.html -->
33<img src="image.jpg" data-src="image2x.png" >
34```
35
36``` javascript
37require("html!./fileA.html");
38// => '<img src="http://cdn.example.com/49e...ba9f/a9f...92ca.jpg" data-src="image2x.png" >'
39
40require("html?attrs=img:data-src!./file.html");
41// => '<img src="image.png" data-src="data:image/png;base64,..." >'
42
43require("html?attrs=img:src img:data-src!./file.html");
44require("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
47require("html?-attrs!./file.html");
48// => '<img src="image.jpg" data-src="image2x.png" >'
49
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,...>'
52
53```
54
55## 'Root-relative' urls
56
57For urls that start with a `/`, the default behavior is to not translate them.
58If a `root` query parameter is set, however, it will be prepended to the url
59and then translated.
60
61With the same configuration above:
62``` html
63<!-- fileB.html -->
64<img src="/image.jpg">
65```
66
67``` javascript
68
69require("html!./fileB.html");
70// => '<img src="/image.jpg">'
71
72require("html?root=.!./fileB.html");
73// => '<img src="http://cdn.example.com/49e...ba9f/a9f...92ca.jpg">'
74
75```
76
77## Interpolation
78
79You can use `interpolate` flag to enable interpolation syntax for ES6 template strings, like so:
80
81```
82require("html?interpolate!./file.html");
83```
84
85```
86<img src="${require(`./images/gallery.png`)}" />
87<div>${require('./partials/gallery.html')}</div>
88```
89
90## License
91
92MIT (http://www.opensource.org/licenses/mit-license.php)