Merge pull request #9318 from jamesgeorge007/hotfix/ease-access-of-emitted-assets
chore: Makes it easier to access contents of emitted assets
This commit is contained in:
commit
ed7d815d61
|
@ -55,6 +55,8 @@ class Compiler extends Tapable {
|
|||
run: new AsyncSeriesHook(["compiler"]),
|
||||
/** @type {AsyncSeriesHook<Compilation>} */
|
||||
emit: new AsyncSeriesHook(["compilation"]),
|
||||
/** @type {AsyncSeriesHook<string, Buffer>} */
|
||||
assetEmitted: new AsyncSeriesHook(["file", "content"]),
|
||||
/** @type {AsyncSeriesHook<Compilation>} */
|
||||
afterEmit: new AsyncSeriesHook(["compilation"]),
|
||||
|
||||
|
@ -430,7 +432,7 @@ class Compiler extends Tapable {
|
|||
: targetFileGeneration + 1;
|
||||
cacheEntry.writtenTo.set(targetPath, newGeneration);
|
||||
this._assetEmittingWrittenFiles.set(targetPath, newGeneration);
|
||||
callback();
|
||||
this.hooks.assetEmitted.callAsync(file, content, callback);
|
||||
});
|
||||
} else {
|
||||
if (source.existsAt === targetPath) {
|
||||
|
@ -445,7 +447,10 @@ class Compiler extends Tapable {
|
|||
|
||||
source.existsAt = targetPath;
|
||||
source.emitted = true;
|
||||
this.outputFileSystem.writeFile(targetPath, content, callback);
|
||||
this.outputFileSystem.writeFile(targetPath, content, err => {
|
||||
if (err) return callback(err);
|
||||
this.hooks.assetEmitted.callAsync(file, content, callback);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
import("./module");
|
||||
|
||||
it("should run", () => {});
|
|
@ -0,0 +1,21 @@
|
|||
module.exports = {
|
||||
output: {
|
||||
futureEmitAssets: true
|
||||
},
|
||||
plugins: [
|
||||
compiler => {
|
||||
const files = {};
|
||||
compiler.hooks.assetEmitted.tap("Test", (file, buffer) => {
|
||||
files[file] = Buffer.isBuffer(buffer);
|
||||
});
|
||||
compiler.hooks.afterEmit.tap("Test", () => {
|
||||
expect(files).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"1.bundle0.js": true,
|
||||
"bundle0.js": true,
|
||||
}
|
||||
`);
|
||||
});
|
||||
}
|
||||
]
|
||||
};
|
|
@ -0,0 +1,3 @@
|
|||
import("./module");
|
||||
|
||||
it("should run", () => {});
|
|
@ -0,0 +1,18 @@
|
|||
module.exports = {
|
||||
plugins: [
|
||||
compiler => {
|
||||
const files = {};
|
||||
compiler.hooks.assetEmitted.tap("Test", (file, buffer) => {
|
||||
files[file] = Buffer.isBuffer(buffer);
|
||||
});
|
||||
compiler.hooks.afterEmit.tap("Test", () => {
|
||||
expect(files).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"1.bundle0.js": true,
|
||||
"bundle0.js": true,
|
||||
}
|
||||
`);
|
||||
});
|
||||
}
|
||||
]
|
||||
};
|
Loading…
Reference in New Issue