Fix AddFile plugin so that it correctly adds files that work in dev mode.

This commit is contained in:
Dillon Kearns 2019-08-19 20:43:37 -07:00
parent 3b64034764
commit 76c91d6108

View File

@ -17,13 +17,15 @@ class AddFilesPlugin {
apply(compiler) { apply(compiler) {
compiler.hooks.afterCompile.tap("AddFilesPlugin", compilation => { compiler.hooks.afterCompile.tap("AddFilesPlugin", compilation => {
this.filesList.forEach(file => { this.filesList.forEach(file => {
compilation.assets[path.join(file.name, "content.txt")] = { // Couldn't find this documented in the webpack docs,
source: function() { // but I found the example code for it here:
return file.content; // https://github.com/jantimon/html-webpack-plugin/blob/35a154186501fba3ecddb819b6f632556d37a58f/index.js#L470-L478
},
size: function() { const filename = path.join(file.name, "content.txt");
file.content.length; compilation.fileDependencies.add(filename);
} compilation.assets[filename] = {
source: () => file.content,
size: () => file.content.size
}; };
}); });
}); });