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
Copy file name to clipboardExpand all lines: README.md
+57-26Lines changed: 57 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,11 +18,12 @@
18
18
19
19
## HTML template as entry point
20
20
21
-
> Define your **source files** of scripts, styles and images directly in HTML template.
21
+
> This plugin allows using a template file as an [entry point](#option-entry).
22
+
23
+
The **HTML Bundler** generates static HTML or [template function](#template-in-js) from [any template](#template-engine) containing source files of scripts, styles, images, fonts and other resources, similar to how it works in [Vite](https://vitejs.dev/guide/#index-html-and-project-root).
24
+
25
+
A template imported in JS will be compiled into [template function](#template-in-js). You can use the **template function** in JS to render the template with variables in runtime on the client-side in the browser.
22
26
23
-
The **Bundler Plugin** generates static HTML or [template function](#template-in-js) from [any template](#template-engine) containing source files of scripts, styles, images, fonts and other resources, similar to how it works in [Vite](https://vitejs.dev/guide/#index-html-and-project-root) or [Parcel](https://parceljs.org/).
24
-
This plugin allows using a template file as an [entry point](#option-entry).
25
-
You can import a template into JS as a compiled [template function](#template-in-js) and render it with variables in runtime on the client-side in the browser.
26
27
27
28
This plugin is an **advanced successor** to `html-webpack-plugin` and a replacement of the [plugins and loaders](#list-of-plugins).
28
29
@@ -100,7 +101,7 @@ You can use a relative path or Webpack alias to a source file.
Start with an HTML template. Add the `<link>` and `<script>` tags.
258
259
You can include asset source files such as SCSS, JS, images, and other media files directly in an HTML template.
259
260
260
-
The plugin resolves `<script src="...">``<link href="...">` and `<img src="...">` that references your script, style and image source files.
261
+
The plugin resolves `<script src="...">``<link href="...">` and `<img src="..." srcset="...">` that references your script, style and image source files.
261
262
262
263
For example, there is the template _./src/views/home.html_:
263
264
@@ -274,15 +275,14 @@ For example, there is the template _./src/views/home.html_:
274
275
<scriptsrc="./main.js"defer="defer"></script>
275
276
</head>
276
277
<body>
277
-
<!-- variable from Webpack config -->
278
-
<h1>Hello <%= name %>!</h1>
278
+
<h1>Hello World!</h1>
279
279
<!-- relative path to image source file -->
280
280
<imgsrc="./picture.png" />
281
281
</body>
282
282
</html>
283
283
```
284
284
285
-
All source filenames should be relative to the current HTML template, or you can use [Webpack alias](https://webpack.js.org/configuration/resolve/#resolvealias).
285
+
All source filenames should be relative to the entrypoint template, or you can use [Webpack alias](https://webpack.js.org/configuration/resolve/#resolvealias).
286
286
The references are rewritten in the generated HTML so that they link to the correct output files.
287
287
288
288
The generated HTML contains URLs of the output filenames:
data: { title:'Sport news' }, // pass variables into template
353
+
},
334
354
},
335
-
// - OR - define a relative or absolute path to page templates
336
-
entry:'src/views/',
355
+
337
356
js: {
338
357
// JS output filename, used if `inline` option is false (defaults)
339
358
filename:'js/[name].[contenthash:8].js',
@@ -560,7 +579,12 @@ See [boilerplate](https://github.com/webdiscus/webpack-html-scss-boilerplate)
560
579
(\*) - `asset/source` works currently for SVG only, in a next version will work for other files too
561
580
562
581
<aid="list-of-plugins"name="list-of-plugins"></a>
563
-
Just one HTML bundler plugin replaces the functionality of the plugins and loaders:
582
+
583
+
#### Why do many developers switch from Webpack to other bundlers?
584
+
One of the reasons they cite is the complex configuration many different plugins and loaders for one simple thing - rendering an HTML page with assets.
585
+
586
+
The HTML bundler plugin "changes the rule of the game", making configuration very simple and clear.
587
+
Just one plugin replaces the functionality of the plugins and loaders:
The `test` option allows to handel only those templates as entry points that match the name of the source file.
1214
1238
1215
1239
For example, if you have other templates, e.g. `*.liquid`, as entry points, then you can set the option to match custom template files: `test:/\.(html|liquid)$/`.
1216
1240
1217
1241
The `test` value is used in the [default loader](#loader-options).
1218
1242
1243
+
> **Note**
1244
+
>
1245
+
> Using the [preprocessor](#loader-option-preprocessor) options will be added the templating engine extensions in the `test` automatically.
1246
+
> Defaults `preprocessor` is [Eta](#loader-option-preprocessor-options-eta) therefore is used the `/\.(html|eta)$/` RegExp.
1247
+
>
1248
+
> For example, if you define the preprocessor option as the [handlebars](#loader-option-preprocessor-options-handlebars), then will be used the `/\.(html|hbs|handlebars)$/` RegExp automatically.
1249
+
1219
1250
**Why is it necessary to define it? Can't it be automatically processed?**
1220
1251
1221
1252
This plugin is very powerful and has many experimental features not yet documented.
0 commit comments