This commit is contained in:
Philipp Dieter 2024-06-24 01:54:21 +02:00
commit 5c6398d480
4 changed files with 1688 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/node_modules/

51
index.js Normal file
View File

@ -0,0 +1,51 @@
const { glob } = require('glob')
const HtmlWebpackPlugin = require('html-webpack-plugin');
class WebpackForceReload {
constructor(options = {}) {
let that = this;
this.options = options;
this.resolvedFiles = [];
console.debug(this.options);
glob.glob(
this.options.files,
{
cwd: this.options.cwd
},
function(err, matches) {
console.debug(matches);
_.forEach(matches, function(value) {
var resolvedFile = path.resolve(value);
that.resolvedFiles.push(resolvedFile);
}
);
});
console.debug(this.resolvedFiles);
}
apply (compiler) {
compiler.hooks.compilation.tap('WebpackForceReload', (compilation) => {
HtmlWebpackPlugin.getHooks(compilation).afterEmit.tapAsync(
'WebpackForceReload',
(data, cb) => {
let forceReload = false;
if (compiler.modifiedFiles) {
compiler.modifiedFiles.forEach((file) => {
if (this.resolvedFiles.includes(file)) {
forceReload = true;
}
});
}
if (this.globalDevServer && forceReload) {
this.globalDevServer.sendMessage(
this.globalDevServer.webSocketServer.clients,
"static-changed"
);
}
cb(null, data)
}
)
})
}
}
module.exports = WebpackForceReload;

1619
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

17
package.json Normal file
View File

@ -0,0 +1,17 @@
{
"name": "webpack-force-reload-plugin",
"version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "AGPL-3.0-or-later",
"devDependencies": {
"glob": "^10.4.2"
},
"dependencies": {
"html-webpack-plugin": "^5.6.0"
}
}