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
Source files will be resolved, processed and auto-replaced with correct URLs in the bundled output.
46
46
-**Inlines**[JS](#recipe-inline-js), [CSS](#recipe-inline-css) and [Images](#recipe-inline-image) into HTML. See [how to inline all resources](#recipe-inline-all-assets-to-html) into single HTML file.
47
+
-[HMR for CSS](#option-css-hot) - update CSS in browser without a full reload.
47
48
- Recompiles the template after changes in the [data file](#option-entry-data) assigned to the entry page as a JSON or JS filename.
48
49
- Generates the [preload](#option-preload) tags for fonts, images, video, scripts, styles.
49
50
- Generates the [integrity](#option-integrity) attribute in the `link` and `script` tags.
@@ -208,6 +209,7 @@ If you have discovered a bug or have a feature suggestion, feel free to create a
208
209
209
210
## 🔆 What's New in v4
210
211
212
+
-**NEW** added supports the [HMR for CSS](#option-css-hot) (since `v4.5.0`).
211
213
-**NEW** added supports the [multiple configurations](https://webpack.js.org/configuration/configuration-types/#exporting-multiple-configurations).
212
214
-**SUPPORTS** Webpack version `5.96+` (since `v4.2.0`).
213
215
-**SUPPORTS** Webpack version `5.81+` (since `v4.0.0`).
@@ -1964,6 +1966,7 @@ type CssOptions = {
1964
1966
chunkFilename?: FilenameTemplate;
1965
1967
outputPath?: string;
1966
1968
inline?:'auto'| boolean;
1969
+
hot?: boolean;
1967
1970
};
1968
1971
```
1969
1972
@@ -1976,19 +1979,22 @@ Default properties:
1976
1979
chunkFilename:'[name].css',
1977
1980
outputPath:null,
1978
1981
inline:false,
1982
+
hot:false,
1979
1983
}
1980
1984
```
1981
1985
1982
1986
- `test` - an RegEpx to process all source styles that pass test assertion
1983
1987
- `filename` - an output filename of extracted CSS. Details see by [filename option](#option-filename).
1984
1988
- `chunkFilename` - an output filename of non-initial chunk files, e.g., a style file imported in JavaScript.
1985
1989
- `outputPath` - an output path of extracted CSS. Details see by [outputPath option](#option-outputpath).
1986
-
- `inline` - inlines extracted CSS into HTML, available values:
1990
+
- `inline` - inject CSS into into HTML at render time, available values:
1987
1991
- `false` - stores CSS in an output file (**defaults**)
1988
1992
- `true` - adds CSS to the DOM by injecting a `<style>` tag
1989
1993
- `'auto'` - in `development` mode - adds to DOM, in `production` mode - stores as a file
1994
+
- `hot` - inject CSS into the DOM at runtime and enable HMR (hot update CSS without a full reload),\
1995
+
similar to how it works in [style-loader](https://github.com/webpack-contrib/style-loader).
1990
1996
1991
-
All source style files specified in `<link href="..." rel="stylesheet">` are automatically resolved,
1997
+
All source style files specified in `<link href="..." rel="stylesheet">` are automatically resolved,
1992
1998
and CSS will be extracted to output file. The source filename will be replaced with the output filename.
1993
1999
1994
2000
For example:
@@ -2022,13 +2028,53 @@ The `[name]` is the base filename of a loaded style.
2022
2028
For example, if source file is `style.scss`, then output filename will be `css/style.1234abcd.css`.\
2023
2029
If you want to have a different output filename, you can use the `filename` options as the [function](https://webpack.js.org/configuration/output/#outputfilename).
2024
2030
2031
+
<a id="option-css-hot" name="option-css-hot"></a>
2032
+
2033
+
#### `css.hot` option
2034
+
2035
+
> ⚠️ Limitation
2036
+
>
2037
+
> - HMR works only for styles imported in JavaScript files. Doesn't works for styles defined directly in HTML via `link` tag.
2038
+
> - Hot update without a full reload works only for styles imported in a last JavaScript file.\
2039
+
> If you have many JS files defined in HTML, where are imported styles, and change a style file imported in the first JS file,
2040
+
> then changes will not be detected in HMR module. You should reload the browser manually.
2041
+
> This behaviour is a BUG in Webpack. The [style-loader](https://github.com/webpack-contrib/style-loader) has exactly same limitation.
2042
+
>
2043
+
2044
+
If you use the [Live Reload](#setup-live-reload) configuration, then be sure to exclude the style files (CSS/SCSS) from watching,
2045
+
otherwise after changes a style file, a page will be full reloaded.
2046
+
2047
+
> ℹ️ Note
2048
+
>
2049
+
> If `devServer` is configured for HRM with styles, then after changing the styles defined in HTML, `Live Reload` will not work for them.
2050
+
> You should then reload the browser self.
2051
+
2052
+
Configuration of `devServer` to enable HMR:
2053
+
2054
+
```js
2055
+
devServer: {
2056
+
static: {
2057
+
directory:path.join(__dirname, 'dist'),
2058
+
},
2059
+
watchFiles: {
2060
+
paths: ['src/**/*.(html|eta)'], // <= exclude *.s?css from watching
2061
+
options: {
2062
+
usePolling:true,
2063
+
},
2064
+
},
2065
+
},
2066
+
```
2067
+
2068
+
**💡 Tip**: to enable HMR for all style files without a full reload, import all those styles in one JS file.
2069
+
2070
+
2025
2071
> ⚠️ **Warning**
2026
2072
>
2027
2073
> Don't use `mini-css-extract-plugin` because the bundler plugin extracts CSS much faster than other plugins.
2028
2074
>
2029
2075
> Don't use `resolve-url-loader` because the bundler plugin resolves all URLs in CSS, including assets from node modules.
2030
2076
>
2031
-
> Don't use `style-loader` because the bundler plugin can auto inline CSS.
2077
+
> Don't use `style-loader` because the bundler plugin can auto inline CSS and HMR.
Copy file name to clipboardExpand all lines: package.json
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
{
2
2
"name": "html-bundler-webpack-plugin",
3
-
"version": "4.4.3",
3
+
"version": "4.5.0",
4
4
"description": "HTML Bundler Plugin for Webpack renders HTML templates containing source files of scripts, styles, images. Supports template engines: Eta, EJS, Handlebars, Nunjucks, Pug, TwigJS. Alternative to html-webpack-plugin.",
0 commit comments