Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Load favicon through html-loader.
Fixes #291.
  • Loading branch information
andreypopp committed Aug 12, 2016
commit 9c21c40f5cc7801da567f82dde229b8cccd7d7ad
3 changes: 0 additions & 3 deletions config/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ if (isInCreateReactAppSource) {
module.exports = {
appBuild: resolveOwn('../build'),
appHtml: resolveOwn('../template/index.html'),
appFavicon: resolveOwn('../template/favicon.ico'),
appPackageJson: resolveOwn('../package.json'),
appSrc: resolveOwn('../template/src'),
appNodeModules: resolveOwn('../node_modules'),
Expand All @@ -47,7 +46,6 @@ if (isInCreateReactAppSource) {
module.exports = {
appBuild: resolveApp('build'),
appHtml: resolveApp('index.html'),
appFavicon: resolveApp('favicon.ico'),
appPackageJson: resolveApp('package.json'),
appSrc: resolveApp('src'),
appNodeModules: resolveApp('node_modules'),
Expand All @@ -59,7 +57,6 @@ if (isInCreateReactAppSource) {
module.exports = {
appBuild: resolveApp('build'),
appHtml: resolveApp('index.html'),
appFavicon: resolveApp('favicon.ico'),
appPackageJson: resolveApp('package.json'),
appSrc: resolveApp('src'),
appNodeModules: resolveApp('node_modules'),
Expand Down
3 changes: 1 addition & 2 deletions config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ module.exports = {
// When you `import` an asset, you get its (virtual) filename.
// In production, they would get copied to the `build` folder.
{
test: /\.(jpg|png|gif|eot|svg|ttf|woff|woff2)(\?.*)?$/,
test: /\.(ico|jpg|png|gif|eot|svg|ttf|woff|woff2)(\?.*)?$/,
include: [paths.appSrc, paths.appNodeModules],
loader: 'file',
query: {
Expand Down Expand Up @@ -169,7 +169,6 @@ module.exports = {
new HtmlWebpackPlugin({
inject: true,
template: paths.appHtml,
favicon: paths.appFavicon,
}),
// Makes some environment variables available to the JS code, for example:
// if (process.env.NODE_ENV === 'development') { ... }. See `env.js`.
Expand Down
3 changes: 1 addition & 2 deletions config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ module.exports = {
{
// "file" loader makes sure those assets end up in the `build` folder.
// When you `import` an asset, you get its filename.
test: /\.(jpg|png|gif|eot|svg|ttf|woff|woff2)(\?.*)?$/,
test: /\.(ico|jpg|png|gif|eot|svg|ttf|woff|woff2)(\?.*)?$/,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally favicon.ico specifically should end up in root build output folder so that browser see it even for files requested from the domain. (Not a big deal but still.)

We could declare a loader entry specifically for it with hardcoded name. However we would have to exclude hash from its name—otherwise it defeats the point. But then we don’t have a way to bump cache. I wonder if Webpack understands name: 'favicon.ico?[hash:8].

Copy link
Contributor Author

@andreypopp andreypopp Aug 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if Webpack understands name: 'favicon.ico?[hash:8]

It does!

include: [paths.appSrc, paths.appNodeModules],
loader: 'file',
query: {
Expand Down Expand Up @@ -181,7 +181,6 @@ module.exports = {
new HtmlWebpackPlugin({
inject: true,
template: paths.appHtml,
favicon: paths.appFavicon,
minify: {
removeComments: true,
collapseWhitespace: true,
Expand Down
1 change: 1 addition & 0 deletions template/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="${require('./src/favicon.ico')}">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

webpack-ism

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a way to make html-loader work just on <link href="./src/favicon.js"> but I don't know how.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to find it :P

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure? require("./src/favicon.js") seems less magical and also consistent with other webpack-isms used (require("./index.css")).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just a weird thing to explain. Imports are natural in JS but odd in HTML. Also since we use ES6 some people won't even know what require is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

<title>React App</title>
</head>
<body>
Expand Down
File renamed without changes.