Skip to content

Commit 0f5277f

Browse files
author
奇风
committed
support webpack 5.0
1 parent a8db09a commit 0f5277f

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

lib/AutoWebPlugin.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ class AutoWebPlugin {
141141
if (Array.isArray(postEntrys)) {
142142
pageEntryArray = pageEntryArray.concat(postEntrys);
143143
}
144-
this.webpackEntry[pageName] = pageEntryArray;
144+
this.webpackEntry[pageName] = {
145+
import: pageEntryArray
146+
};
145147
});
146148
}
147149

lib/WebPlugin.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const path = require('path');
22
const fs = require('fs');
33
const querystring = require('querystring');
4-
const { SyncHook } = require('tapable');
54

65
const util = require('./util');
76
const HTMLDocument = require('./HTMLDocument');
@@ -95,9 +94,6 @@ class WebPlugin {
9594
const { options } = this;
9695
const { template, requires, filename, outputPagemap, outputPagemapFilename } = options;
9796

98-
// inject hooks
99-
compiler.hooks.webPluginBeforeEmitHTML = new SyncHook(['htmlDocument']);
100-
10197
// get webpack compiler's env
10298
if (global._isProduction === undefined) {
10399
global._isProduction = util.isProduction(compiler);
@@ -111,9 +107,9 @@ class WebPlugin {
111107
// watch for file changed event
112108
compiler.hooks.watchRun.tap('WebPlugin', (watching) => {
113109
// 发生变化的文件列表
114-
const changedTimes = watching.watchFileSystem.watcher.mtimes;
110+
const changedTimes = watching.watchFileSystem?.watcher?.mtimes;
115111
// 如果 HTML 模版文件发生了变化就重新编译模版文件
116-
if (changedTimes[template] !== undefined) {
112+
if (changedTimes && changedTimes[template] !== undefined) {
117113
// html template file has changed, re build this.htmlDocument
118114
this.buildHtmlDocument();
119115
}
@@ -158,7 +154,6 @@ class WebPlugin {
158154
});
159155

160156
// get html document string
161-
compiler.hooks.webPluginBeforeEmitHTML.call(this.htmlDocument);
162157
const htmlOut = this.htmlDocument.serialize();
163158
// add it to webpack output files
164159
util.addFileToWebpackOutput(compilation, filename, htmlOut);

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "web-webpack-plugin",
3-
"version": "4.6.7",
3+
"version": "5.0.0",
44
"description": "web plugin for webpack, alternatives for html-webpack-plugin, use HTML as entry",
55
"keywords": [
66
"webpack",
@@ -51,8 +51,7 @@
5151
"dependencies": {
5252
"file-type": "^8.1.0",
5353
"parse5": "^5.0.0",
54-
"tapable": "^1.1.3",
55-
"webpack": "^4.16.0"
54+
"webpack": "^5"
5655
},
5756
"devDependencies": {
5857
"@types/react": "^16.4.7",

0 commit comments

Comments
 (0)