Skip to content

Commit 8c09b71

Browse files
committed
Treat created files as compliation assets
1 parent 17c8c8d commit 8c09b71

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

index.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,18 @@ var CreateFilePlugin = (function () {
2323
this.options = options;
2424
}
2525

26-
function _createFile(filePath, fileName, content) {
27-
return () => {
28-
const fullPath = path.join(filePath, fileName);
29-
write.sync(fullPath, content);
30-
}
31-
}
32-
3326
CreateFilePlugin.prototype.apply = function (compiler) {
34-
const createFile = () => _createFile(this.options.path, this.options.fileName, this.options.content);
27+
compiler.hooks.emit.tap({ name: 'CreateFileWebpack' }, compilation => {
28+
const relativePath = path.join(this.options.path, this.options.fileName);
29+
const targetPath = path.join(compiler.options.output.path, relativePath);
3530

36-
if (!!compiler.hooks) {
37-
compiler.hooks.done.tap('CreateFileWebpack', createFile());
38-
} else {
39-
compiler.plugin('done', createFile());
40-
}
31+
write.sync(targetPath, this.options.content);
32+
33+
compilation.assets[relativePath] = {
34+
source: () => this.options.content,
35+
size: () => this.options.content.length
36+
};
37+
});
4138
};
4239

4340
return CreateFilePlugin;

0 commit comments

Comments
 (0)