-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for favicon #32
Conversation
return /^favicon\.ico($|\?)/.test(path.basename(module.name)); | ||
}); | ||
if (assets.favicon) { | ||
assets.favicon = webpackStatsJson.publicPath + assets.favicon.assets[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if webpack has some nice util that will make this less manual?
Unfortunately this does not work with the new template mode ( |
Why do we have to set favicon to true? |
Ah, didn't think of that. I'll give it a whack 😄
The thought is that it is a potentially heavy operation (my project at work has over 1000 assets). I suppose it's not too much either way, node is pretty fast... What do you think? |
We do sth similar with the manifest. |
@jantimon Added support for |
Would it be possible to specify a path for favicon in the options and load it like |
It would also be nice if this also allowed to specify files for |
@jantimon Unless I want to include any I'll see if I can get it working without manually requiring. I can then add the same logic for |
@jantimon I think that we can't use how |
@jantimon Added support for I also removed the option, it's now automatically picked up |
@jantimon I expanded the PR to also cover any extra file you may want. I can separate it into it's own PR if you'd like, but it builds on this one, so I thought I'd keep them together |
yeah I guess the extra file should be in an extra pull request for now. |
@jantimon Ok, removed those changes |
@jantimon Found a bug if an image was base64-encoded. Should be ready for review now 😄 |
return [path.parse(module.name).name, publicPath + module.assets[0]]; | ||
} | ||
|
||
return [path.parse(module.name).name, module.source.substring(18, module.source.length - 1)]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
module.exports = "
as well as the last "
@jantimon Any chance this could get merged (or feedback, if it's missing something)? If you're enjoying the weekend, ignore my nagging 😄 I'd like to see this in before tomorrow, as I'll need it at work, though. |
@@ -70,6 +70,27 @@ HtmlWebpackPlugin.prototype.emitHtml = function(compilation, htmlTemplateContent | |||
}; | |||
}; | |||
|
|||
HtmlWebpackPlugin.prototype.getAssetPathFromModuleName = function(publicPath, modules) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be better to extract some if these functions into a lib/
directory or something, as this file is getting a bit bulky, and there's no real need to export anything but the constructor and the apply
-function. I can make a separate PR moving stuff around though
Hi @SimenB thanks for all your work. Unfortunately I am on a conference for the next days but I'll take a look at it. |
@jantimon Ah, OK. The proxy at work kills GitHub dependencies. I'll just publish a fork in the meantime, then deprecate when (if) you merge it 😄 |
Here is a first try to solve the favicon (based on your changes) I removed the apple icon for now as it didn't allow to specify multiple dimensions e.g. <link rel="apple-touch-icon" sizes="76x76" href="/apple-touch-icon-76x76.png" />
<link rel="apple-touch-icon" sizes="120x120" href="/apple-touch-icon-120x120.png" />
<link rel="apple-touch-icon" sizes="152x152" href="/apple-touch-icon-152x152.png" /> Another big change was that it uses a similar way to add the What do you think? |
@jantimon Oooh, those changes look much cleaner! Great job! Regarding apple icons, I thought about the different sizes, but as h5bp removed them (h5bp/html5-boilerplate#1367), and now recommend using just one (h5bp/html5-boilerplate#1622), I thought it was fine to just include the one size. |
Although I really like the idea with the extra files I am not sure wether this is just an edge case or a common use case. It is already possible to pass a custom templateContent function which has access to everything needed to use these files. You are correct the base64 encoding is missing as it doesn't use the loaders. The h5bp is referring only to the file name and is a solid starting point for creating web sites however imho there are still use cases where you would like to provide different icon versions depending on the size. I rebase this pr into #37 for the new 1.4.0 release but I would like to get the feedback of @ampedandwired before merging. |
The us case behind extra files is that I don't want to know how to iterate through the files in my template, or how Webpack inner structure works. I just want this and that file in my template. I have no idea how to send it through loaders, ref #10. Would be awesome though! As my use case for this was just favicon, I think it is covered by #37. I'd like to see if we can reach a consensus on #36 though. I'll rebase after |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Ref #28
This is supposed to be a temporary solution until #10 is implemented.
A file named
favicon.ico
has to be included manually in somerequire
, which I suppose is bad, but until #10 is done, I don't see any way around it