From 0e3461afa11a6f36bc61bff3acd79687f912f5e2 Mon Sep 17 00:00:00 2001 From: HerrHase Date: Sun, 8 Sep 2024 15:19:37 +0200 Subject: [PATCH] bugfix for emit in manifest, add check parameter for svg --- index.js | 2 +- manifest.js | 11 ++++++++--- package.json | 2 +- plugins/manifest.js | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 78a8b8e..948c744 100644 --- a/index.js +++ b/index.js @@ -101,7 +101,7 @@ module.exports = function tinyComponentsWebpack(files, options = {}) { } // adding svg src - if (defaults.svg.src) { + if (defaults.svg && defaults.svg.src) { config.plugins.push(new SvgSpritemapPlugin(defaults.svg.src, { output: { filename: 'symbol-defs.svg', diff --git a/manifest.js b/manifest.js index 12f3cb4..c74b080 100644 --- a/manifest.js +++ b/manifest.js @@ -49,7 +49,12 @@ class Manifest { Object.keys(files).forEach((key) => { files[key].forEach((file) => { - this._results[stats.publicPath + file] = stats.publicPath + file + '?version=' + this._hash(file, stats.outputPath) + + const filePath = stats.outputPath + '/' + file + + if (fs.existsSync(filePath)) { + this._results[stats.publicPath + file] = stats.publicPath + file + '?version=' + this._hash(filePath) + } }) }) @@ -64,9 +69,9 @@ class Manifest { * @return {string} * */ - _hash(file, outputPath) { + _hash(filePath) { - const data = fs.readFileSync(outputPath + '/' + file, 'utf8') + const data = fs.readFileSync(filePath, 'utf8') const hash = crypto .createHash('md5') .update(data) diff --git a/package.json b/package.json index 96b0c9c..9621e66 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tiny-components/webpack", - "version": "0.5.1", + "version": "0.5.2", "description": "Webpack Wrapper", "repository": { "type": "git", diff --git a/plugins/manifest.js b/plugins/manifest.js index 626c889..3fe0e5c 100644 --- a/plugins/manifest.js +++ b/plugins/manifest.js @@ -31,7 +31,7 @@ class ManifestPlugin { // create manifest object const manifest = new Manifest(this._filename, this._context) - compiler.hooks.emit.tapAsync(pluginName, (compilation, callback) => { + compiler.hooks.afterEmit.tapAsync(pluginName, (compilation, callback) => { const stats = compilation.getStats().toJson() manifest.run(stats)