Skip to content

Commit aff956c

Browse files
committed
work on readme
1 parent a153f49 commit aff956c

File tree

1 file changed

+58
-1
lines changed

1 file changed

+58
-1
lines changed

README.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,60 @@
11
# HTML Webpack Inject Preload
2-
A html webpack plugin for injecting <link rel='preload'>
2+
A [HTML Webpack Plugin](https://github.com/jantimon/html-webpack-plugin) for injecting <link rel='preload'>
33

4+
This plugin allows to add preload links anywhere you want.
5+
6+
# Installation
7+
8+
```
9+
npm i -D @principalstudio/html-webpack-inject-preload
10+
```
11+
12+
**webpack.config.js**
13+
14+
```js
15+
const HtmlWebpackPlugin = require('html-webpack-plugin');
16+
const HtmlWebpackInjectPreload = require('@principalstudio/html-webpack-inject-preload');
17+
18+
module.exports = {
19+
entry: 'index.js',
20+
output: {
21+
path: __dirname + '/dist',
22+
filename: 'index_bundle.js'
23+
},
24+
plugins: [
25+
new HtmlWebpackPlugin(),
26+
new HtmlWebpackInjectPreload({
27+
files: [
28+
{
29+
match: /.*\.woff2/,
30+
attributes: { rel: 'preload', as: 'font', type: 'font/woff2', crossorigin: true },
31+
},
32+
{
33+
match: /vendors\.[a-z-0-9]*.css/,
34+
attributes: { rel: 'preload', as: 'style' },
35+
},
36+
],
37+
})
38+
]
39+
}
40+
```
41+
42+
43+
**HTML file**
44+
45+
Add `<!-- html-webpack-inject-preload -->` to indicate where to inject preload links.
46+
47+
```html
48+
<!DOCTYPE html>
49+
<html>
50+
<head>
51+
<meta charset="utf-8">
52+
<title>Webpack App</title>
53+
<!-- html-webpack-inject-preload -->
54+
<link href="dist/main.css">
55+
</head>
56+
<body>
57+
<script src="index_bundle.js"></script>
58+
</body>
59+
</html>
60+
```

0 commit comments

Comments
 (0)