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