Skip to content

Commit

Permalink
feat: use webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS to add f…
Browse files Browse the repository at this point in the history
…avicons
  • Loading branch information
jantimon committed Jan 20, 2021
1 parent 0c5e4ff commit c697725
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const chunkSorter = require('./lib/chunksorter.js');
const getHtmlWebpackPluginHooks = require('./lib/hooks.js').getHtmlWebpackPluginHooks;
const { assert } = require('console');

const fsStatAsync = promisify(fs.stat);
const fsReadFileAsync = promisify(fs.readFile);

class HtmlWebpackPlugin {
Expand Down Expand Up @@ -469,24 +468,13 @@ function hookIntoCompiler (compiler, options, plugin) {
*/
function addFileToAssets (filename, compilation) {
filename = path.resolve(compilation.compiler.context, filename);
return Promise.all([
fsStatAsync(filename),
fsReadFileAsync(filename)
])
.then(([size, source]) => {
return {
size,
source
};
})
return fsReadFileAsync(filename)
.then(source => new webpack.sources.RawSource(source, true))
.catch(() => Promise.reject(new Error('HtmlWebpackPlugin: could not load file ' + filename)))
.then(results => {
.then(rawSource => {
const basename = path.basename(filename);
compilation.fileDependencies.add(filename);
compilation.assets[basename] = {
source: () => results.source,
size: () => results.size.size
};
compilation.emitAsset(basename, rawSource);
return basename;
});
}
Expand Down

0 comments on commit c697725

Please # to comment.