Skip to content

Commit

Permalink
Merge pull request #12 from drolsen/dev
Browse files Browse the repository at this point in the history
Dev 1.3.0 Release
  • Loading branch information
drolsen authored Jan 21, 2022
2 parents c9816af + f58e26e commit a95fbde
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 8,043 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Option | Type | Description

### Tests

Webpack Favicons comes with one `test`.
Webpack Favicons comes with a few `test`s.
These helps ensure that both favicons get written to disk and that link tags are injected into any HTML assets within the larger Webpack build process.

Simply run `npm run test` or `yarn test` from the root of the plugin to run test.
Expand Down
55 changes: 30 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require('fs');
const path = require('path');
const favicons = require('favicons');
const { sources } = require('webpack');

class WebpackFavicons {
constructor(options) {
Expand Down Expand Up @@ -52,11 +52,11 @@ class WebpackFavicons {
compilation.hooks.processAssets.tapPromise(
{
name: 'WebpackFavicons',
stage: compilation.PROCESS_ASSETS_STAGE_PRE_PROCESS, // see below for more stages
stage: compilation.PROCESS_ASSETS_STAGE_ADDITIONAL, // see below for more stages
additionalAssets: true
},
(assets) => {
return favicons(
return import('favicons').then((module) => module.favicons(
this.options.src,
this.options,
(error, response) => {
Expand All @@ -69,6 +69,7 @@ class WebpackFavicons {
this.files = response.files;
this.images = response.images;

// Adds favicon markup to any html documents
Object.keys(assets).map((i) => {
// limit assets to only .html files
if (i.indexOf('.html') !== -1) {
Expand All @@ -87,8 +88,32 @@ class WebpackFavicons {
);
}
});

// Adds generated images to build
if (this.images) {
Object.keys(this.images).map((i) => {
let image = this.images[i];
assets[path.normalize(`/${this.options.path}/${image.name}`).replace(/\\/g, '/')] = {
source: () => image.contents,
size: () => image.contents.length
};
});
}

// Adds manifest json and xml files to build
if (this.files) {
Object.keys(this.files).map((i) => {
let file = this.files[i];
assets[path.normalize(`/${this.options.path}/${file.name}`)] = {
source: () => file.contents,
size: () => file.contents.length
};
});
}

return assets;
}
);
));
}
);
});
Expand All @@ -102,27 +127,7 @@ class WebpackFavicons {
additionalAssets: false
},
(assets) => {
// Adds generated images to build
if (this.images) {
Object.keys(this.images).map((i) => {
let image = this.images[i];
assets[path.normalize(`\/${this.options.path}/${image.name}`)] = {
source: () => image.contents,
size: () => image.contents.length
};
});
}

// Adds manifest json and xml files to build
if (this.files) {
Object.keys(this.files).map((i) => {
let file = this.files[i];
assets[path.normalize(`\/${this.options.path}/${file.name}`)] = {
source: () => file.contents,
size: () => file.contents.length
};
});
}

}
);
});
Expand Down
Loading

0 comments on commit a95fbde

Please sign in to comment.