Skip to content

Commit 52b23c9

Browse files
committed
Update for Webpack 5
Fixes #6
1 parent 1cedb6d commit 52b23c9

File tree

7 files changed

+1136
-2986
lines changed

7 files changed

+1136
-2986
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This plugin allows to add preload links anywhere you want.
55

66
# Installation
77

8-
You need to have HTMLWebpackPlugin v4 to make this plugin work.
8+
You need to have HTMLWebpackPlugin v5 to make this plugin work.
99

1010
```
1111
npm i -D @principalstudio/html-webpack-inject-preload

package-lock.json

Lines changed: 1109 additions & 2965 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@principalstudio/html-webpack-inject-preload",
3-
"version": "1.1.1",
3+
"version": "1.2.0",
44
"description": "A html webpack plugin for injecting <link rel='preload'>",
55
"main": "lib/main.js",
66
"types": "lib/main.d.ts",
@@ -31,21 +31,19 @@
3131
},
3232
"homepage": "https://github.com/principalstudio/html-webpack-inject-preload#readme",
3333
"devDependencies": {
34-
"@types/jest": "^26.0.14",
35-
"@types/mini-css-extract-plugin": "^0.9.1",
36-
"@types/node": "^14.11.8",
37-
"@types/webpack": "^4.41.22",
38-
"@typescript-eslint/parser": "^4.4.1",
39-
"css-loader": "^4.3.0",
40-
"eslint": "^7.11.0",
41-
"file-loader": "^6.1.1",
42-
"html-webpack-plugin": "^4.5.0",
43-
"jest": "^26.5.3",
44-
"mini-css-extract-plugin": "^1.0.0",
45-
"prettier": "^2.1.2",
46-
"ts-jest": "^26.4.1",
47-
"typescript": "^4.0.3",
34+
"@types/jest": "^26.0.20",
35+
"@types/node": "^14.14.22",
36+
"@typescript-eslint/parser": "^4.14.0",
37+
"css-loader": "^5.0.1",
38+
"eslint": "^7.18.0",
39+
"file-loader": "^6.2.0",
40+
"html-webpack-plugin": "5.0.0-beta.6",
41+
"jest": "^26.6.3",
42+
"mini-css-extract-plugin": "^1.3.4",
43+
"prettier": "^2.2.1",
44+
"ts-jest": "^26.4.4",
45+
"typescript": "^4.1.3",
4846
"url-loader": "^4.1.1",
49-
"webpack": "^5.1.0"
47+
"webpack": "^5.17.0"
5048
}
5149
}

src/main.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ class HtmlWebpackInjectPreload implements WebpackPluginInstance {
8585
compilation.chunks.forEach(chunk => {
8686
chunk.files.forEach((file: string) => assets.add(file));
8787
});
88-
console.log(assets);
8988

9089
const linkIndex = htmlPluginData.headTags.findIndex(
9190
tag => tag.tagName === 'link',
@@ -102,10 +101,13 @@ class HtmlWebpackInjectPreload implements WebpackPluginInstance {
102101
href = href[0] === '/' ? href : '/' + href;
103102

104103
if (file.match.test(asset)) {
105-
const preload = {
104+
const preload: HtmlTagObject = {
106105
tagName: 'link',
107106
attributes: Object.assign(file.attributes, {rel: 'preload', href}),
108107
voidTag: true,
108+
meta: {
109+
plugin: 'html-webpack-inject-preload'
110+
}
109111
};
110112

111113
if (linkIndex > -1) {

test/index.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ const options: HtmlWebpackInjectPreload.Options = {
2929
describe('HTMLWebpackInjectPreload', () => {
3030
it('webpack plugin', done => {
3131
const compiler = webpack({
32+
mode: 'production',
33+
context: path.resolve(__dirname),
3234
entry: path.join(__dirname, 'entry.js'),
3335
module: {
3436
rules: [
@@ -52,7 +54,7 @@ describe('HTMLWebpackInjectPreload', () => {
5254
},
5355
output: {
5456
path: path.join(__dirname, 'dist'),
55-
publicPath: path.resolve(__dirname),
57+
publicPath: '/',
5658
},
5759
plugins: [
5860
new MiniCssExtractPlugin() as WebpackPluginInstance,

test/style.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@
77
body {
88
font-family: Roboto, sans-serif;
99
background-color: red;
10+
color: white;
11+
}
12+
13+
body::before {
14+
content: 'Hello world'
1015
}

tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
/* Raise error on expressions and declarations with an implied 'any' type. */
1616
"esModuleInterop": true,
1717
/* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
18-
"typeRoots": ["node_modules/@types", "typings"],
1918
"lib": [
2019
"es2019"
2120
],

0 commit comments

Comments
 (0)