Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
3 changes: 2 additions & 1 deletion src/lib/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ if (process.env.NODE_ENV==='development') {
require('preact/devtools');
}
else if ('serviceWorker' in navigator && location.protocol === 'https:') {
navigator.serviceWorker.register('/sw.js');
// eslint-disable-next-line no-undef
navigator.serviceWorker.register(__webpack_public_path__ + 'sw.js');
Copy link

Choose a reason for hiding this comment

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

@developit Please take a look at this and decide finally about the solution. I really need this feature in my project :-)
In my opinion it is a nice solution, what are your concerns?

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with this, webpack will never change this var name and it keeps the resolution at runtime.

}


Expand Down
2 changes: 1 addition & 1 deletion src/resources/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<link rel="manifest" href="/manifest.json">
<link rel="manifest" href="<%= htmlWebpackPlugin.files.publicPath %>manifest.json">
Copy link

Choose a reason for hiding this comment

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

For me it works right now -
<link rel="manifest" href="<%= __webpack_public_path__ %>manifest.json">,
why can't we use this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to stay away from __webpack_public_path__ where possible. I think it is generally bad practice to be reading from that as it is mutable and not so reliavle. For lib/entry.js I used __webpack_public_path__ because it is the only available reference in the context.

I understand the inconsistency, but let me know what you think!

Copy link

Choose a reason for hiding this comment

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

Yes, it is mutable, and this how webpack itself proposes to use this variable if the publicPath's value is not known at compilation time, so you can even set it in the entry point.

<% if (htmlWebpackPlugin.options.manifest.theme_color) { %>
<meta name="theme-color" content="<%= htmlWebpackPlugin.options.manifest.theme_color %>">
<% } %>
Expand Down