You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By default every assets (`<img src="./image.png">`) is transpiled to it's own module request (`import HTML__URL__O from './image.png'`) to be correctly handled by `webpack`.
27
+
By default asset requests (`<img src="./image.png">`) are transpiled to their own module requests (`import HTML__URL__O from './image.png'`) to be correctly handled by `webpack` as an ES Module
28
28
29
-
> ⚠️ You need to specify loaders for your assets (e.g images) separately in your `webpack.config.js`, like the `file-loader` or `url-loader`, to handle these requests.
29
+
> ⚠️ You need to specify additional loaders for your assets (e.g images) separately in your `webpack.config.js`, like the `file-loader` or `url-loader`, to handle these requests.
30
30
31
+
**webpack.config.js**
31
32
```js
32
33
{
33
34
test:/\.html$/,
@@ -38,13 +39,33 @@ By default every assets (`<img src="./image.png">`) is transpiled to it's own mo
38
39
}
39
40
```
40
41
42
+
### `Caching`
43
+
44
+
If your application includes many HTML Components or certain Components are of significant size, we highly recommend to use the [`cache-loader`](https://github.com/webpack-contrib/cache-loader) for persistent caching these components for faster rebuilds
45
+
46
+
**webpack.config.js**
47
+
```js
48
+
{
49
+
test:/\.html$/,
50
+
use: [
51
+
'cache-loader',
52
+
{
53
+
loader:'html-loader',
54
+
options: {}
55
+
}
56
+
]
57
+
}
58
+
```
59
+
60
+
41
61
<h2align="center">Options</h2>
42
62
43
63
|Name|Type|Default|Description|
44
64
|:--:|:--:|:-----:|:----------|
45
-
|**`url`**|`{Boolean}`|`true`| Enable/Disable HTML Assets (`<img src="./file.png">`)|
46
-
|**`import`**|`{Boolean}`|`true`| Enable/Disable HTML Imports (`<import src="./file.html">`)|
47
-
|**`template`**|`{Boolean}`|`false`|Export HTML as a template `{Function}`|
65
+
|**[`url`](#url)**|`{Boolean}`|`true`| Enable/Disable HTML Assets (`<img src="./file.png">`)|
66
+
|**[`import`](#import)**|`{Boolean}`|`true`| Enable/Disable HTML Imports (`<import src="./file.html">`)|
67
+
|**[`template`](#template)**|`{Boolean\|String}`|`false`|Export HTML as a template `{Function}`. The template placeholder defaults to `<div>${ _.x }</div>` (`_`)|
68
+
|**[`minimize`](#minimize)**|`{Boolean}`|`false`|Enable/Disable HTML Minification|
48
69
49
70
### `url`
50
71
@@ -74,6 +95,22 @@ By default every assets (`<img src="./image.png">`) is transpiled to it's own mo
74
95
75
96
#### `{Boolean}`
76
97
98
+
**file.html**
99
+
```html
100
+
<div>
101
+
<p>${ _.txt }</p>
102
+
</div>
103
+
```
104
+
105
+
**file.js**
106
+
```js
107
+
importtemplatefrom'./file.html'
108
+
109
+
consthtml=template({ txt:'Hello World!' })
110
+
111
+
document.body.innerHTML= html
112
+
```
113
+
77
114
**webpack.config.js**
78
115
```js
79
116
{
@@ -84,21 +121,88 @@ By default every assets (`<img src="./image.png">`) is transpiled to it's own mo
84
121
}
85
122
```
86
123
124
+
#### `{String}`
125
+
126
+
Set a custom name for the template scope
127
+
128
+
**file.html**
129
+
```html
130
+
<div>
131
+
<p>${ $.txt }</p>
132
+
</div>
133
+
```
134
+
135
+
**file.js**
136
+
```js
137
+
importtemplatefrom'./file.html'
138
+
139
+
consthtml=template({ txt:'Hello World!' })
140
+
141
+
document.body.innerHTML= html
142
+
```
143
+
144
+
**webpack.config.js**
145
+
```js
146
+
{
147
+
loader:'html-loader',
148
+
options: {
149
+
template:'$'
150
+
}
151
+
}
152
+
```
153
+
154
+
### `minimize`
155
+
156
+
#### `{Boolean}`
157
+
158
+
**webpack.config.js**
159
+
```js
160
+
{
161
+
loader:'html-loader',
162
+
options: {
163
+
minimize:true
164
+
}
165
+
}
166
+
```
167
+
87
168
#### `{Object}`
88
169
170
+
Pass custom [options](https://github.com/posthtml/htmlnano#modules) for minification
171
+
89
172
**webpack.config.js**
90
173
```js
91
174
{
92
175
loader:'html-loader',
93
176
options: {
94
-
template: {...locals } // TODO add method to pass locals
0 commit comments